为了账号安全,请及时绑定邮箱和手机立即绑定

wordpress 中的总自定义帖子类型

wordpress 中的总自定义帖子类型

PHP
慕无忌1623718 2022-12-23 16:13:59
你好,在这个插件中,我为 cpt1 和 cpt2 写了这 2 个代码总帖子,现在我希望代码获得这 2 个 CPT 自定义帖子类型的总数 /// 这意味着 // menha_dir_ltg + mobadra1_dir_ltg = ??? 任何的想法//this is to count totala custom post -- mobadra2_dir_ltg - ta7tag da3madd_shortcode('total-listing-counter-menha','total_listing_counterـmenha');function total_listing_counterـmenha(){ $count_posts = wp_count_posts( 'menha_dir_ltg' )->publish; return $count_posts;}//this is to count totala custom post -- mobadra1_dir_ltg - ta7tag da3madd_shortcode('total-listing-counter-ta7tag-da3m','total_listing_counterـta7tagـda3m');function total_listing_counterـta7tagـda3m(){ $count_posts = wp_count_posts( 'mobadra1_dir_ltg' )->publish; return $count_posts;}
查看完整描述

1 回答

?
慕码人8056858

TA贡献1803条经验 获得超6个赞

您只需将两者结合在第三个简码中并更新“$total_count”变量:


add_shortcode('total-listing-counter','total_listing_counter');


function total_listing_counter(){


     $count_menha_dir_ltg_posts = wp_count_posts( 'menha_dir_ltg' )->publish;

     $count_mobadra1_dir_ltg_posts = wp_count_posts( 'mobadra1_dir_ltg' )->publish;

     $total_count = count_menha_dir_ltg_posts + $count_mobadra1_dir_ltg_posts;


     return $total_count;


}


查看完整回答
反对 回复 2022-12-23
  • 1 回答
  • 0 关注
  • 56 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信