WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to combine displaying a list of custom post types on a single page depending on conditional tags?

Below is what I have so far, basically if there are 4 posts or less show the posts, if there are more than 4 posts show another list.

Currently it just shows the first list, though.

<?php $loop = new WP_Query( array( 'post_type' => 'cases','posts_per_page' => '-1') ); ?>

<?php if ($wp_query->found_posts <= 4) { ?>

    <!--4 and less posts -->
    <ul class="case-list clearfix">

        <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
            <li id="<?php the_ID(); ?>"><?php the_title(); ?></li>
        <?php endwhile; wp_reset_postdata();?>


<?php } else { ?>

    <!--4 and above posts -->
    <ul class="case-thumbs clearfix">

        <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
            <li id="<?php the_ID(); ?>"><?php the_title(); ?></li>
        <?php endwhile; wp_reset_postdata();?>


<?php } ?>
share|improve this question
Well, your WP_Query is stored in $loop, and yet you check $wp_query...? – tfrommen Apr 22 '13 at 10:59
Oh, and the loops (and thus the posts) are exactly the same, BTW. I did not check that before because of the $wp_query. So what list do you want to show if there are more than 4 posts? You did not set up the according query, right? – tfrommen Apr 22 '13 at 11:12
I get the impression assumptions were made by the asker that require the answerers to posess psychic powers. Sadly my crystal ball is out of service today and clarification is necessary. I suggest you write out what you want in pseudocode, and be precise/specific. There's a lack of detail here, and it's causing confusion – Tom J Nowell Apr 22 '13 at 11:22
My mistake the stored $loop needed to go in the found_posts. Thank you for your help.. stupid mistake. – user4630 Apr 22 '13 at 12:20

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.