[resolved] Custom posts query does not work on index with paged var (5 posts)

  1. adrian7
    Posted 4 years ago #

    I just updated my blog to wp 3.4, and I noticed a bug. Well for me it is a bug and I need a workaround.

    I have the following code in my theme's index.php:

    global $wp_query;
    $paged = intval( get_query_var('paged') );
    query_posts(array('post_type' => array('post', 'movie', 'director', 'actor'), 'paged'=>$paged));

    Based on THIS query a pagination is generated later on the page.
    But clicking on the "Older posts" link gives me 404 page.

    Guess that's because wp compares the paged var ONLY with the number of "posts" and I have only 12 posts and 20 items set to display on the page.

    The pagination worked fine untin wo 3.4!

  2. deepbevel
    Posted 4 years ago #

    Can't explain why it would change, custom queries can be weird. I'm pretty sure I've done it a bit differently, maybe something like this:

      $temp = $wp_query;
      $wp_query= null;
      $wp_query = new WP_Query(array('post_type' => array('post', 'movie', 'director', 'actor'), 'paged'=>$paged));
    while ($wp_query->have_posts()) : $wp_query->the_post();
    <?php // the usual post-displaying codes here ?>
      $wp_query = null; $wp_query = $temp; ?>

    if no go you may take a look here

  3. adrian7
    Posted 4 years ago #

    Thanks for the quick reply deepbevel, however that does not solve my problem, as my code is not even reached, it just goes to the 404 template (dumb WP :P).

    I have modified my code as follows:

    $paged = intval( get_query_var('paged') ); if($paged > 0 ) die("We hit paged!");

    As I expected on /page/2/ there's no die!
    So guess it is a real bug after all!

  4. deepbevel
    Posted 4 years ago #

    Sorry, thought the querry worked and it was only the paging not happening.

    that's kinda disturbing, I haven't updated wp on my site which uses a few custom queries, Although I'm not currently using paging.

  5. adrian7
    Posted 3 years ago #

    With help from @ocean90 I solved the apparent "bug". Here's the solution: http://core.trac.wordpress.org/ticket/21522#comment:3

Topic Closed

This topic has been closed to new replies.

About this Topic