WordPress.org

Support

Support » Alpha/Beta » [Resolved] “Sticky” Qualifier for query_posts

[Resolved] “Sticky” Qualifier for query_posts

  • 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 15 replies - 1 through 15 (of 22 total)
  • I think this should do it:
    query_posts(array('post__in'=>get_option('sticky_posts')));

    does get_option(‘sticky_posts’) return a comma separated list of all posts that have the sticky option selected?

    Nevermind … it seems like it returns an array of Post IDs for posts that have been marked sticky.

    This new feature needs some serious documentation. The possibilities of the sticky options are much greater than just “sticking a post to the homepage”.

    Thank you Otto42, it worked 🙂

    Thank you Otto42, I’ve got that example working to fetch only sticky post.

    Now, on the same page (in a different loop), I’d like to fetch posts that are NOT sticky. So, I’d like to exclude those marked as sticky.

    My front page has a feature box at the very top that I’d like to designate as the sticky spot, and then, I have separate blocks for the posts within each category. Right now, the sticky-spot is working great, thanks to your suggestion, but I can’t figure out a way to exclude sticky posts from the others.

    Specifically, I have code that looks somewhat like this:

    <?php query_posts('showposts=3&cat=6'); ?>
    <?php while (have_posts()) : the_post(); ?>
    ... stuff ...
    <?php endwhile; ?>

    I’m wondering how I can modify my query_posts so that I can exclude those marked as sticky

    MichaelH

    @michaelh

    I’m wondering how I can modify my query_posts so that I can exclude those marked as sticky

    The Excluding Sticky Posts from Custom Queries section of Migrating Plugins and Themes to 2.7 explains that you just need to add caller_get_posts=1 to your query string.

    oh man, this looks like a lot of new, cool functions to diddle with *sigh*

    My understanding of “caller_get_posts=1” means that it still fetches ALL posts with the category, it just doesn’t bring the sticky to the top.

    So, if I have …
    <?php query_posts('caller_get_posts=1&showposts=3&cat=6'); ?>
    … it will still bring back the sticky posts.

    So, it sounds like that’s the fix for me, but it’s really not.

    Help?

    MichaelH

    @michaelh

    lairdf might have to resort to the is_sticky conditional tag.

    Thank you MichaelH, I’ll definitely try!

    lairdf, did you figure it out? I’m trying to do the exact same thing. can’t get a query returned that excludes the sticky posts.

    I am working on a new site and wanted to use the new sticky function to create a highlight area (“Items to watch”). Otto’s solution works great to pull the sticky posts out, but if there are no sticky posts, it is returning the regular stream of posts and spits out the number of them defined in the settings panel.

    anyone have a way to degrade something like this in case there are no posts specified as sticky?

    I used:

    query_posts(array(
    	"post__not_in"		=>	get_option("sticky_posts")
    ));

    to get rid of all the sticky posts in the loop. Strange that it’s not in the documentation. Worked for me, hope it works for you too 🙂

    Incorporated some of the ideas from this thread into:
    http://codex.wordpress.org/Template_Tags/query_posts#Sticky_Post_Parameters

    @nathanrice

    The possibilities of the sticky options are much greater than just “sticking a post to the homepage”.

    If you have more examples or ideas, please add them to the Codex and thanks for doing so.

Viewing 15 replies - 1 through 15 (of 22 total)
  • The topic ‘[Resolved] “Sticky” Qualifier for query_posts’ is closed to new replies.
Skip to toolbar