• Resolved Nathan Rice

    (@nathanrice)


    Does anyone know of a way to use query_posts to pull only posts marked as “Sticky” using the new sticky feature in 2.7?

Viewing 7 replies - 16 through 22 (of 22 total)
  • wprabbit: Did you solve your issue?

    I have the same problem: if there’s no sticky post the loop is returning 10 regular posts.

    Sometimes asking a question is just what it takes to solve the problem.

    <?php
    if (get_option('sticky_posts')) {
    
    // Do this if there is any sticky post.
    
    }
    
    else {
    
    // Do this if there isnt.
    
    }
    ?>

    Thanks a lot, this help me !

    thank you jordiromkema and nathan!

    nathan’s definite guide to sticky posts has been invaluable, and jordironmkema, the post_not_in code elegantly replaces a hacked block of code.

    Thanks!

    I’m having a different problem, using Atahualpa, where I have query_posts to include only one category on homepage:

    <?php
    if (is_home()) {
    query_posts(“cat=4”);
    }
    ?>

    but when I use that, the formatting I’ve applied to sticky posts disappears. Atahualpa folks say it’s not their issue. Any thoughts?

    I’m bumping this.

    I want to use the loop as I usually would, except I’m using query_posts to get the posts from a specific category. How can I use query_posts and still get the sticky posts at the top?

    `query_posts(array(
    “post__not_in” => get_option(“sticky_posts”)
    ));`

    I’ve used this solution but it’s not working for me. I’m using it in the second loop in my home.php file, which is preceded by wp_reset_query().

    The first loop uses this wp_query:
    query_posts(array('post__in'=>get_option('sticky_posts')));

    The second uses:
    query_posts(array("post__not_in"=>get_option("sticky_posts")));

    But I see the same (sticky) post as the first post produced by both loops. In date order it would be the third post.

    Any idea why this wouldn’t work?

Viewing 7 replies - 16 through 22 (of 22 total)
  • The topic ‘“Sticky” Qualifier for query_posts’ is closed to new replies.