Display different number of posts from one category on the different pages

You can check for the existence of a variable, so you don’t overwrite it:

add_action( 'pre_get_posts', 'wpse7262_pre_get_posts' );
function wpse7262_pre_get_posts( &$wp_query )
{
    if ( $wp_query->is_category() ) {
        if ( ! array_key_exists( 'post_type', $wp_query->query_vars ) ) {
            $wp_query->set( 'post_type', 'game' );
        }
        if ( ! array_key_exists( 'posts_per_page', $wp_query->query_vars ) ) {
            $wp_query->set( 'posts_per_page', 9 );
        }
    }
}

Leave a Comment