Hide if Custom Post Type is empty

I am not new to WordPress but one of my projects drives me insane.
The request is to completely hide a DIV if the Custom Post Type has no content. I found several tutorials to Hide Empty Custom Fields, but this request? Is it even possible?

Below is the SourceCode to have an idea of the actual DIV and the CPT. So basically at the moment there’s no post in the CPT but the DIV is displayed. But I want to make it disappear when there’s no content and make it appear if there’s content.

The current template is a One-Page WordPress Website.

<div id=”tour” class=”block” style=”margin-top: 50% !important;”>
<h3 class=”block”>tour > </h3>
<div class=”row events”>
<?php $query = new WP_Query( array( ‘post_type’ => ‘tour’ ) );
$postnum = 0;
if ( $query->have_posts() ) : ?>
<?php while ( $query->have_posts() ) : $query->the_post(); ?>
<div class=”col-sm-4 text-left event-cell isold”>
<h3><?php the_title(); ?></h3>
<h4>Date: <?php echo get_post_meta($post->ID, ‘eventdate’, true); ?></h4>
<h4><?php echo get_post_meta($post->ID, ‘eventlocation’, true); ?><br/>Starts at: <?php echo get_post_meta($post->ID, ‘eventtime’, true); ?></h4>
<div>/////////////////////<br/>
<?php echo get_post_meta($post->ID, ‘eventtype’, true); ?></div>
</div>
<?php $postnum++; // Increment counter
if ($postnum == 3){ ?>
<div class=”clearfix hidden-xs”></div>
<?php } ?>
<?php endwhile;?>
<?php else : ?>
<?php endif; ?>
</div>
</div>

Read more here:: <a href=https://wordpress.stackexchange.com/questions/296753/hide-div-if-custom-post-type-is-empty target="_blank" title="Hide

if Custom Post Type is empty” rel=nofollow>Hide

if Custom Post Type is empty

Leave a Reply

Your email address will not be published. Required fields are marked *