I have a lot of scheduled posts (location) in my db, and i want to show only the taxonomies (locationtype), which have published posts.
therefore i created a check_term_posts($term_id) function
but it always returns 0.
WP Query seems to be the only way to accomplish that, as $term->count seems to deliver everything.
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 is always zero