• Just finished upgrading two sites to WordPress 2.5 and everything went quite smooth (or so I thought). On reviewing the site, I noticed that all templates where I used query_posts were broken.

    This used to work:
    query_posts('showposts=5&author=10');
    if (have_posts()):
    while ($my_query->have_posts()):
    endwhile;
    endif;

    Now it doesn’t. I’ve been messing around with $wp_query and WP_QUERY all morning, but no luck.

    Any ideas? Is it my code? If so, what should I be doing?

    Thanks.

Viewing 9 replies - 1 through 9 (of 9 total)
  • There is no global object in WordPress named $my_query, and there never has been.

    Perhaps you used to do something like

    $my_query = query_posts('showposts=5&author=10');

    That might make sense, but it seems unnecessary to perform the WP “Loop”.

    Thread Starter Jeffrey Barke

    (@jeffreyb)

    Thanks filosofo; that’s my fault. Some of the code I posted earlier was wrong and I may not have been explicit enough about my problem.

    Prior to upgrading from WordPress 2.0.9 to 2.5, the following page displayed all the posts I’ve ever written. After the upgrade, it only shows five of my posts.
    https://themechanism.com/blog/author/jeffreybarke/

    Here’s the actual code on the page:

    <?php
    query_posts('showposts=-1&author=' . $curauth->ID);
    if (have_posts()) : ?>
    <ul>
    <?php while (have_posts()): the_post(); ?>
    Some HTML output here
    <?php endwhile; ?>
    </ul>
    <?php endif; ?>

    The code did not change, but its behavior did. Do you know why?

    Thanks.

    I don’t know why it doesn’t work for you; the same code for me works just fine.

    You could either use the next_posts_link and previous_posts_link template tags within the while loop, to generate page links, or you could specify a really large number of posts to show instead of -1.

    Thread Starter Jeffrey Barke

    (@jeffreyb)

    Unfortunately, none of the parameters work. showposts=-1, showposts=1, showposts=5, and showposts=100 all return the same thing: five posts.

    I’m going to test the query_posts() function on other blogs I’ve upgraded to 2.5 and see if it works correctly there (I assume it will).

    Thanks for the suggestions, though!

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    Unfortunately, none of the parameters work. showposts=-1, showposts=1, showposts=5, and showposts=100 all return the same thing: five posts.

    Then I’d say that you have something else overriding it somewhere else, because query_posts() works fine for me.

    Thread Starter Jeffrey Barke

    (@jeffreyb)

    You’re correct, Otto42. Sorry for the time, everyone, but thanks for looking into this.

    The problem was, of course, a plugin. Post-upgrade, I enabled the plugins one-by-one while refreshing the homepage; everything seemed to be working fine. I missed the fact that one of them messed with the query since no errors were thrown and the misbehavior is only evident on certain pages.

    The plugin in question was Adhesive.

    Thanks,
    Jeffrey

    WP 2.6 with the plugin WP-Sticky 1.31 (a plugin by Gamerz which replaces Adhesive), has the same negative effect of messing up my custom query_posts arguments.

    In my case I had a page which was an alphabetical index of all my post titles. I have query_posts with orderby=title & sortposts=-1 (which means sort them alphabetically and show all)

    I noticed it stopped working and researched several possibilities before I found this thread. This saved me some headache. Thanks.

    Did you delete the wp-admin and wp-includes folders when you upgraded or did you overwrite them?

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘query_posts() broken in WordPress 2.5?’ is closed to new replies.