【发布时间】:2019-05-16 08:40:09
【问题描述】:
我的数据库中有很多预定的帖子(位置),我只想显示已发布帖子的分类法(位置类型)。
因此我创建了一个 check_term_posts($term_id) 函数
但它总是返回 0。
WP Query 似乎是实现这一目标的唯一方法,因为 $term->count 似乎可以提供一切。
protected function check_term_posts($term_id) {
$args = [
'posts_per_page' => -1,
'post_type' => 'location',
'post_status' => 'publish',
'tax_query' => [[
'taxonomy' => 'locationtype',
'field' => 'term_id',
'terms' => $term_id
]]
];
$q = new \WP_Query($args);
return $q->post_count;
}
$q->post_count 始终为零
【问题讨论】:
-
看到这个stackoverflow.com/questions/12250957/… 。它使用“id”字段而不是“term_id”进行分类。