WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] Custom posts query does not work on index with paged var

[Resolved] Custom posts query does not work on index with paged var

  • 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));
    
    get_header();

    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!

Viewing 4 replies - 1 through 4 (of 4 total)
  • 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:

    <?php
      $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 ?>
    
    <?php
      endwhile;
      $wp_query = null; $wp_query = $temp; ?>

    if no go you may take a look here

    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!

    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.

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

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Resolved] Custom posts query does not work on index with paged var’ is closed to new replies.
Skip to toolbar