get_query_var( ‘paged’ ) not working outside of homepage

Twenty Eleven Theme…

On the home page, I have successfully filtered the loop to display just “Featured” posts with pagination functioning properly through nav links. I’m trying to display posts from all categories on another page called “Unfiltered.” Why do the nav links disappear when used on this other page?

edit: if I change the value of ‘paged’ to ‘1’ or ‘2’, I get the 10 posts that I would expect to so ‘paged’ seems to work depending on the value I set, just not when I set it to get_query_var( ‘paged’ )

            <?php /* $paged = ( get_query_var('page') ) ? get_query_var('page') : 1;*/

            $unfiltered_query = new WP_Query ( 

            array (
                'posts_per_page' => 10,
                'paged' =>  get_query_var( 'paged' )
            ) 

        );?>

        <?php if ( $unfiltered_query->have_posts() ) : ?>

            <?php twentyeleven_content_nav( 'nav-above' ); ?>

            <?php /* Start the Loop */ ?>

                <?php while ( $unfiltered_query->have_posts() ) : $unfiltered_query->the_post(); ?>

                <?php get_template_part( 'excerpt', get_post_format() ); ?>

            <?php endwhile; ?>

            <?php twentyeleven_content_nav( 'nav-below' ); ?>

4 s
4

twentyeleven_content_nav() uses the main query object, $wp_query. You’ll need to use the $wp_query variable, rather than $unfiltered_query, then wp_reset_query() to restore the original $wp_query (which it’ll find in $wp_the_query, something you should probably avoid touching directly).

As long as you’re careful to restore the original query, you’re in good shape.

I would submit a patch to core that allows twentyeleven_content_nav() to optionally take a query object which it can use for its calculations.

Leave a Comment