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.

according with Pagination with custom loop. I use the custom loop for display flash game. For make a pagination on the page with posts from one category (mydomain/category/categoryName) I used:

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

I have the section on the main page of my site, where displayed three game from each category. But according with code above I can't display only 3 games, even if I determine in array('post_per_page', 3) or smth like this, because this number have been already determine in $wp-query. how could I kill two birds with one stone? Thanks.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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 );
        }
    }
}
share|improve this answer
    
oh, thanks again! –  glazsasha Feb 8 '11 at 10:26

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.