Reputation: 524
There's a couple of problems I need solved here.
1) I can't seem to get this to only list the parent categories.
2) Is there a way I can also show the number of trashed posts next to where I echo $live_posts
<ul>
<?php
$categories = get_categories();
foreach ($categories as $cat) {
$posts = new WP_Query( array(
'depth' => 1,
'post_status' => array('publish'),
'cat' => $cat->cat_ID));
$live_posts = $posts->post_count;
?>
<li>
<a href="#"><?php echo $cat->cat_name; ?> (<?php echo $live_posts; ?>)</a>
</li>
<?php }
?>
</ul>
Regarding the first problem, I thought 'depth' => 1 was supposed to limit to the parents, but for reasons unknown it's not working. Unless I'm missing something obvious?
Thanks in advance!
Upvotes: 1
Views: 2121
Reputation: 319
$args = array(
'taxonomy' => 'category',
'orderby' => 'name',
'order' => 'ASC',
'parent' => 0,
'hide_empty' => false,
);
$the_query = new WP_Term_Query($args);
$categories = $the_query->get_terms();
print_r($the_query);
exit;
Upvotes: 0