I am currently running a query to pull in all terms of a taxonomy and list the posts under each term.
What i have done is working fine. I have tried to add in the “hide_empty” argument and set it to false so i can display the empty terms. For some reason it just isn’t working.
Here is my query:
<?php
// List posts by the terms for a custom taxonomy of any post type
$post_type = 'streams';
$tax = 'programmes';
$tax_terms = get_terms('programmes', array(
'hide_empty' => 0,
'hierarchical' => 0
) );
if ($tax_terms) {
foreach ($tax_terms as $tax_term) {
$args = array(
'post_type' => $post_type,
"$tax" => $tax_term->slug,
'post_status' => 'publish',
'posts_per_page' => -1,
'caller_get_posts'=> 1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) : ?>
<p class="breadcrumb"><?php echo $tax_term->name; ?></p>
<ul class="taxlist">
<?php while ( $my_query->have_posts() ) : $my_query->the_post(); ?>
<li id="post-<?php the_ID(); ?>">
<a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
</li>
<?php endwhile; // end of loop ?>
</ul>
<?php else : ?>
<?php endif; // if have_posts()
wp_reset_query();
} // end foreach #tax_terms
}
?>
Any help would be greatly appreciated.
Cheers, Dan
You are looping through the Taxonomy Terms, but you are not outputting anything if there are no Posts that are associated with the Term currently being looped. If you are looking to output the
$term->nameregardless, you should change that section of the code to this –