• My wp-pagenavi has stopped working, it now shows the page, e.g if I click on page 2 it will show as page 2, but it’s still showing the posts from page 1? I haven’t installed any new plugins or updated anything, so i’m at a bit of a loss as to why this has started happening? Any help would be most appreciated! Thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter SteveL23

    (@marybyker)

    According to Scribu,
    “Say you have something like this:
    query_posts(‘cat=8’);
    or like this:
    query_posts( array( ‘cat’ => 8 ) );
    You just need to pass along the ‘paged’ query var from the main query:
    query_posts( array( ‘cat’ => 8, ‘paged’ => get_query_var(‘paged’) ) );
    If that doesn’t work, you can also try passing the ‘page’ query var:
    query_posts( array( ‘cat’ => 8, ‘paged’ => get_query_var(‘page’) ) );

    I actually have this:

    <?php
                                    $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
    
    				$wp_query = new WP_Query (array(
    				   'paged' => $paged,
    				   'posts_per_page' => 3,
    				   'order' => 'DESC',
    				   'cat' => '-1077, -1076',
    				   'post__not_in' => get_option( 'sticky_posts' )
    				));
    
                                    if ($wp_query->have_posts()) : while($wp_query->have_posts()) : $wp_query->the_post();?>

    I’m really unsure as to where to put Scribu’s code? Any suggestions? I’m not a PHP coder i’m afraid, so it’s a bit intimidating!

    Hi,

    Looking at the documentation, I think the following code would work:

    <?php
    
    // Get paged or page if available
    $paged = ( get_query_var('paged') ) ? get_query_var('paged') : get_query_var( 'page' );
    
    $my_query = new WP_Query (array(
    	'paged' => $paged,
    	'posts_per_page' => 3,
    	'order' => 'DESC',
    	'cat' => '-1077, -1076',
    	'post__not_in' => get_option( 'sticky_posts' )
    ));
    
    if ( $my_query->have_posts() ) :
    	while( $my_query->have_posts() ) : $my_query->the_post();
    		// Do other loop stuff here
    	endwhile;
    endif;
    
    // Now display pagenavi
    if ( function_exists( 'wp_pagenavi' ) ) :
    wp_pagenavi( array(
    	// Pass our own query variable
    	'query' => $my_query,
    ) );
    else :
    // Bring in default next/previous page links
    endif;
    
    // Avoid side effects
    wp_reset_query();
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Stopped showing older posts when clicking on next page’ is closed to new replies.