Support

Account

Home Forums Front-end Issues CPT shows blog posts when CPT is empty?

Helping

CPT shows blog posts when CPT is empty?

  • I have a product reviews CPT through ACF and it works fine, except when there are no posts published to the CPT. Instead it will show the list of blog posts. I’d like it to show the “No posts found.” Here is the code:

    
    <main id="post-type__<?php echo $type;?>">
    		
    <section class="archive-title">
     <div class="container container__archive-title container--wide">
      <h1 class="category-title fs--huge"><?php echo single_cat_title( '', false );?></h1>
     </div>
    </section>
    		
    		
    <?php
    	
     $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;	
    		
    $args = array(
      'cat' => $cat,
      'post_type' => $type,
      'post_status' => 'publish',
      'paged' => $paged
    );
    	
    	
    	
    $reviewscpt = new WP_Query( $args );
    
    if( $reviewscpt->have_posts()) :		
    $reviewcount = 0;?>
    
    <section class="collection collection__archive--reviews">
     <div class="container container__archive--reviews">
                    
      <ul class="archive__loop archive__loop--reviews loop">
       <?php while( $reviewscpt->have_posts() ): $reviewscpt->the_post(); $reviewcount++;?>
        <li class="loop-article review-article-<?php echo $reviewcount;?>">
         <div class="collection__col collection__col--left">
          <h1 class="loop-article__title fs--med">
           <a>"><?php the_title(); ?></a>
          </h1>
    
           <p class="loop-article__excerpt"><?php the_excerpt(); ?></p>
           <div class="loop-review__cta">
            <p class="link link--lined link--review loop-article__cta">
             <a>">Read Review</a>
            </p>
            <p class="callout__link review__buy-link loop-article__cta">			
             <a>">
              <?php echo get_field('review_product_link_text', $post->ID);?></a>
            </p>
    								
    
          </div>
         </div>
    
         <div class="collection__col collection__col--right">
          <a>">
         <?php the_post_thumbnail(); ?>
          </a>
         </div>
    						
    </li>
    <div class="review-archive__divider">
    						
    </div>
    <?php endwhile; ?>
    </ul>
                    
    </div>
    </section>
            
    
    <div class="loop__nav">
    <?php 
      
    echo paginate_links( array(
              'format' => 'page/%#%',
              'current' => max( 1, get_query_var('paged') ),
              'total' => $reviewscpt->max_num_pages,
              'prev_text' => '«',
              'next_text' => '»'
         ) );?>
    
    </div>
    
    <?php else: ?>
    <p>It looks like that's the end of the blog posts!</p>
    <?php endif; ?>
    		
    		
    
    	
    
    <?php do_action('core_' . $type . '_category_after_loop');?>
    		
    
    </main>
    
  • What is the value of $type?

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.