I have a custom post type called products with product_categories as its taxonomy name. It contains categories which each have subcategories and posts.
I want to display a count of all posts in the subcategories only.
Here is what I have so far:
<?php
// POSTS LOOP
// Query
$args = array( 'post_type' => 'products' , 'orderby' => 'menu_order', 'order' => 'ASC' ,
'tax_query' => array(
array(
'taxonomy' => 'product_categories',
'terms' => array(14),
'include_children' => false
)
));
$query = new WP_Query( $args );
// Post Counter
$term_id = 14;
$tax_name = 'product_categories';
$terms = get_terms($tax_name, array('parent' => 0));
$term_children = get_term_children($term_id,$tax_name);
$post_count = 0;
// Loop Structure
echo '<ul>';
while ( $query->have_posts() ) : $query->the_post();
echo '<li class="zazzoo-page">';
foreach($terms as $term) {
$term_children = get_term_children($term->term_id,$tax_name);
echo '<ul>';
foreach($term_children as $term_child_id) {
$term_child = get_term_by('id',$term_child_id,$tax_name);
$post_count = $term_child->count;
echo '<div class="zazzoo-counter">'. $post_count .' Designs</div>';
}
echo '</ul>';
} ?>
<div class="title-border"><div class="page-title"><?php the_title(); ?></div></div>
<div class="hovereffect">
<?php the_post_thumbnail('zazzoo-thumb', array('class' => 'responsive-img')); ?>
<div class="overlay">
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
</div>
</div>
<?php echo '</li>';
endwhile;
echo '</ul>';
wp_reset_query();
?>
Above is an image of what it currently looks like. Brochures and Card Tags (in which there are 4 posts each) are subcategories that the post count value should display on and the rest are posts.
I'm still learning WordPress theme development so if anyone can offer some guidance, it would be greatly appreciated.