1

Here is my template for archive-people.com:

It currently only shows the first 10 people. I'd like it to show everyone, not just the first 10 people.

<?php get_header(); ?>
<div id="content" class="clearfix row-fluid">
<div id="main" class="span12 clearfix" role="main">
    <?php if ( have_posts() ) : while (have_posts()) : the_post(); ?>
    <div class="person-card">
        <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
            <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail( 'thumbnail' ); ?><br />
            <?php the_title(); ?></a>
        </div>
    </div>
    <?php 
        endwhile; 
        endif;
    ?>
</div>
</div>
<?php get_footer(); ?>

If I want it to display everyone, is that something I change in the template? Or is that something that I add to the functions.php file?

1 Answer 1

2

In function.php

add_action('pre_get_posts','show_all_people');

function show_all_people( $query ) {
  if ( $query->is_main_query() && is_post_type_archive('people') ) {
    $query->set('posts_per_page', -1);
  }
}

See Codex docs for pre_get_posts hook

2
  • This may have changed recently but the docs say to use $query->is_main_query() inside of pre_get_posts. This is in the under the hood section of this page: codex.wordpress.org/Function_Reference/is_main_query
    – trueinViso
    Commented Jun 27, 2015 at 2:22
  • 1
    @trueinViso is_main_query() in 'pre_get_posts' was disabled in 3.7. Answer updated. Thanks.
    – gmazzap
    Commented Jun 27, 2015 at 8:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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