【发布时间】:2021-09-20 19:56:52
【问题描述】:
在我的 WordPress v5.8.1 中,我在 taxonomy.php 中有以下查询以获取帖子列表。
$args = array(
'post_type' => array('song', 'dance'),
'post_status' => 'publish',
'posts_per_page' => 10,
);
query_posts($args);
查询返回来自post_type 的帖子。
我想在同一页面中创建一个菜单,我想在其中检查查询结果是否找到了来自特定 post_type 的帖子。菜单看起来像这样。
-
此分类有来自 Song、Dance 的帖子(如果找到来自两个 post_type 的帖子)或
-
此分类有来自 Song 的帖子(如果找到来自 Song post_type 的帖子)
在循环中尝试了以下内容:
$song_count = wp_posts_count('song')->found_posts;
$dance_count = wp_posts_count('dance')->found_posts;
if ($song_count=>0 {
/** code goes here **/
}
Above 返回整个 WordPress 的计数,而不仅仅是当前分类法。
【问题讨论】: