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

How do I show 10 posts on the first page of the archive, and 20 on others (>1)?

My custom post type name is "apartments".


share|improve this question
up vote 3 down vote accepted

You can change the posts_per_page variable depending on the page you are on, so make it 10 on the first page and 20 on the other pages. However, you will have to modify the offset query variable too, otherwise you will skip posts 11-20 on the second page, because this page thinks they are already displayed on the first page.

add_action( 'pre_get_posts', 'wpse15087_pre_get_posts' );
function wpse15087_pre_get_posts( &$wp_query )
    if ( $wp_query->is_post_type_archive( 'apartments' ) ) {
        if ( ! $wp_query->is_paged() ) {
            $wp_query->set( 'posts_per_page', 10 );
        } else {
            $wp_query->set( 'posts_per_page', 20 );
            $wp_query->set( 'offset', ( ( $wp_query->get( 'paged' ) - 2 ) * 20 ) + 10 );
share|improve this answer
nice answer, thanks Jan! – ilovewordpress Apr 19 '11 at 11:16

Your Answer


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.