Support » Fixing WordPress » Pagination Not Working

  • Hey guys,

    I am having an issue with pagination..

    currently i am using a combination of buddypress and wordpress.. and to handle pagination a plugin called wp-pagenavi

    it is working great at detecting how many posts per page, and how many pages it needs to create.. generating a list of links at the desired location on the page that link to etc. code is below:

    <?php $my_query = new WP_Query( array( 'posts_per_page'=>5, 'author' => bp_displayed_user_id(), 'paged' => get_query_var('paged') ) ); ?>
      <?php if ( $my_query->have_posts() ) : ?>
         <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
         <?php endwhile; ?>
      <?php if(function_exists('wp_pagenavi')) { wp_pagenavi(array( 'query' => $my_query )); } ?>
    <?php endif; ?>

    However, when i click on one of the links it redirects me back to the homepage… is there something i am missing that would do this??

    Any help would be greatly appreciated, Thank you in advance!


Viewing 6 replies - 1 through 6 (of 6 total)
  • try to change this:
    'paged' => get_query_var('paged')

    into this:
    'paged' => get_query_var('page')

    (as far as can see, it is not totally clear what to use)

    Show Posts from Current Page

    Display posts from current page:

    $query = new WP_Query( 'paged=' . get_query_var( 'page' ) );
    Pagination Note: You should set get_query_var( 'page' ); if you want your query to work with pagination. Since WordPress 3.0.2, you do get_query_var( 'page' ) instead of get_query_var( 'paged' ). The pagination parameter ‘paged’ for WP_Query() remains the same.

    Thread Starter haxxxton


    thanks for the reply alchymyth,

    unfortunately it still didnt solve the problem.. also to test the change i did the following

    <?php echo "PAGE: ".get_query_var('paged'); ?>


    <?php echo "PAGE: ".get_query_var('page'); ?>

    the result was

    PAGE: 0



    so i have left it as paged as it seems to result in an output at least..

    this is still linking back to the homepage on clicking any of the links :S
    im thinking that maybe buddypress is doing something messed up to the code… im just surprised as if it was going to link to a page that doesnt exist then i should get a 404 error not a redirect :S

    there doesnt appear to be a page redirect call in the .htaccess or the header.php file

    so confused

    Thread Starter haxxxton


    ok.. more things to add to this as its now getting rather confusing

    the page url where the pagination is wanting to occur looks like this

    now i have found no matter what i type after this url it ALWAYS redirects me to the home page UNLESS there is actually another page there..

    stays on the new page because it exists..

    now because pagination with pagenavi uses the link below to change which page its on the blog is automatically redirecting me

    is there a way to stop this from happening?

    at the minute im having to code a work around using get data.. which doesnt force the redirect..

    Anonymous User 8099256



    I had the same problem here but, the issue has something to do with the setting that you will find here “Seetings > Reding > Blog pages show at most > Type the number that you need

    I have a paged query that is not working even though I have set everything correctly, but the issue I guess is the global variables of maximum posts per page that overrides the “posts_per_page” variable from the “query_posts”.

    Hope this works,

    Anonymous User 8099256


    Little update here: it has nothing to do with the permalink structure.

    I was trying to add pagination to my plugin;

    and i had the same problem… on buddypress page like profile page get_query_var(‘page/paged’) don’t work correctly.

    So I found $bp->action_variables, now it works with code like this;

    if (!$page = intval(get_query_var(‘paged’))) {
    global $bp;
    $page = intval($bp->action_variables[0]);

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Pagination Not Working’ is closed to new replies.