WordPress.org

Forums

[resolved] Multiple query_posts (2 posts)

  1. fruitattack
    Member
    Posted 7 years ago #

    I have a theme where I'm listing the latest posts of a specific category in the header. But the problem I've run into is that when I use query_posts('showposts=1&cat=3'), the main Loop is also affected, and will only show one post of that category.

    Also affected are pages and categories which will show whatever query_posts got previously.

    Is there a workaround for this?

    What I'm essentially trying to do is post the latest post from a specific category, and the code for that comes before the main Loop which is supposed to list the latest posts overall. By using query_posts before the Main loop, it causes the main loop to also display what query posts called up.

    I've tried query_posts('showposts=10') to no avail. It works fine for the home page, but when it comes to individual pages and categories, the posts it displays are the same.

  2. After you are finished with your extra query_posts, use this to reset it back to the defaults for whatever you're supposed to be looking at:
    wp_reset_query();

Topic Closed

This topic has been closed to new replies.

About this Topic