query_posts() problems (2 posts)

  1. sancho
    Posted 9 years ago #


    I have a home.php template that creates a new WP_Query object then shows 2 posts from the blog. After the <?php endwhile; ?> I have two query_posts() functions, one filtering for posts in cat=10 the other for posts in cat=-10 (ie. all other categories) that both include the same mini-index template.

    The second one isn't working, it lists nothing. The code is:
    <?php rewind_posts(); ?>
    <?php query_posts('cat=10'); //gets all posts from category 10
    load_template( TEMPLATEPATH . '/mini-index.php'); //loads home page category links
    <?php query_posts('cat=-10'); //gets all posts from categories other than 10
    load_template( TEMPLATEPATH . '/mini-index.php'); //loads home page category links


  2. yosemite
    Posted 9 years ago #

    Query_posts can be used to control which posts show up in The Loop....

    ...Place a call to query_posts() in one of your Template files before The Loop begins....

    Above from http://codex.wordpress.org/Template_Tags/query_posts

    Note: I didn't see a question in your post, so I'm guessing here, but it looks like you're expecting query_posts to return posts and it won't. It just changes the query used in the following Loop.

Topic Closed

This topic has been closed to new replies.

About this Topic