This is on a CPT archive with Taxonomy terms , i can't get the 'No posts found' to show up ? the loop works , it displays each term name as a heading and shows the posts under each term in a list. I have tried a lot of code to get the 'No posts found' to show up ... nothing is working ?
<?php
//fetch the terms for the policy taxonomy
$terms = get_terms( 'policy-groups', array(
'hide_empty' => 'true',
) );
// run a query for each policy-group term
foreach( $terms as $term ) :
$args = array(
'post_type' => 'policies',
'policy-groups' => $term->slug ,
'order' => 'DSC',
'posts_per_page' => -1,
);
$query = new WP_Query( $args );
if( $query->have_posts() ) : ?>
<ul>
<?php
// output the policy-group name in a heading tag
echo'<h4 class="policy-archive-heading">' . $term->name . '</h4>';
// Start while the Loop
while ( $query->have_posts() ) : $query->the_post();
$attachment_id = get_field( "policy_upload" );
$url = wp_get_attachment_url( $attachment_id );
?>
<li>
<a href="<?php echo $url; ?>" target="_blank"><?php the_title( ); ?></a>
</li>
<?php endwhile; //endwhile ?>
<?php else: printf( __('<strong>Sorry , No posts were found</strong>')); ?>
<?php endif; //end if posts ?>
</ul>
<?php endforeach ?>
// use reset postdata to restore orginal query
wp_reset_postdata();