php - wordpress 中的自定义帖子类型总数
问题描述
你好,在这个插件中,我为 cpt1 和 cpt2 编写了这 2 个代码总帖子,现在我想要代码得到这 2 个 CPT 自定义帖子类型的总数 /// 这意味着 // menha_dir_ltg + mobadra1_dir_ltg = ??? 任何想法
//this is to count totala custom post -- mobadra2_dir_ltg - ta7tag da3m
add_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 da3m
add_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;
}
解决方案
您只需将两者结合在第三个短代码中并更新“$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;
}
推荐阅读
- java - 上下文表单循环中的多个 RestTemplateBuilders
- excel - 基于带有宏的模板创建第二个文档后文件损坏
- ios - 当应用程序进入后台时,您的应用程序中有 FaceID 或 touchID 是否会停止在后台播放音频?
- azure-devops - 有什么方法可以限制哪些池可以为 Artifact 提要做出贡献?
- c++ - 使用 Ceres Solver 求解非线性系统:编译问题
- java - 如何保留 POJO 中定义的 JSON 响应顺序
- google-chrome-extension - 更新网址时如何禁用内容脚本?
- android - 离子卡滚动错误
- python - 组合的组合
- html - Bootstrap 4 个垂直选项卡和右侧的内容