I have pieced together the following code but can't quite get it to work as I need it to.
I'm using Advanced Custom fields to add a PDF upload to my custom post type ('software_pdf' field) so it needs to look at all the posts for that custom post type and if there are no PDF's uploaded to anyone of them, display a message 'No Data Available.'
If there is a PDF attached to any of the posts, it needs to not show the message and instead list just the titles that have a PDF attached.
My issue is that it lists the titles with PDF's attached but it also still shows the 'No Data Available' message and I am stuck on how to resolve that. Any help would be appreciated, thanks!
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$custom_loop = new WP_Query(array(
'paged' => $paged,
'post_type' => 'Products',
'cat' => 5,
'posts_per_page' => 25,
'orderby' => 'name',
'order' => 'ASC',
));
if ( $custom_loop->have_posts() ) :
while ( $custom_loop->have_posts() ) : $custom_loop->the_post();
global $post;
$softwarepdf = get_field('software_pdf');
if (empty( $softwarepdf ) ) { ?>
<p class="nodata">No Data Available.</p>
<? }
else if (!empty( $softwarepdf ) ) { ?>
<p class="productthumbtitle"><?php the_title(); ?></p>
PDF
<? }
endwhile;
wp_reset_query();
endif;
Aucun commentaire:
Enregistrer un commentaire