Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have 6 posts with a custom post type in my Wordpress theme. I want to show them all on a page but I can only get a maximum of 3 to show up, regardless of how many there are.

I have this code in the page:

<?php $count_posts = wp_count_posts( 'cases' )->publish;
echo $count_posts; ?>

<?php query_posts('post_type=cases'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div class="post" style="display:inline;">case</div>
<?php endwhile; else: ?>
<p>Sorry, no posts matched your criteria.</p>
<?php endif; ?>

...and it outputs this:

6
case case case

Why are my other 3 custom posts not showing up?

Thanks in advance

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

If you don't set a value for posts_per_page, it will use whatever the setting is for Blog pages show at most under Settings > Reading.

Also, don't use query_posts, use WP_Query instead:

$args = array(
    'post_type' => 'cases',
    'posts_per_page' => -1 // get all cases
);
$cases = new WP_Query( $args );
if ( $cases->have_posts() ) :
    while ( $cases->have_posts() ) :
        $cases->the_post();
        // output case
    endwhile;
else:
    // nothing found
endif;
share|improve this answer
    
YES! Solved. Thank you so much!!!!! –  mradbourne Sep 22 '13 at 15:47
add comment

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.