Sticky Posts in WordPress

Sticky Posts WordPress That PHP Girl

WordPress 3.1 may still be in the testing phases, but it doesn’t hurt to prepare! I was searching through the codex for the query_posts formatting tonight and found this about sticky posts:

Sticky Post Parameters

Sticky posts first became available with Version 2.7. Posts that are set as Sticky will be displayed before other posts in a query, unless excluded with the ignore_sticky_posts=1 parameter. Note that ignore_sticky_posts replaced the caller_get_posts argument in Version 3.1.

  • array(‘post__in’=>get_option(‘sticky_posts’)) – returns array of all sticky posts
  • ignore_sticky_posts=1 – To ignore (or exclude) sticky posts being included at the beginning of posts returned, but the sticky post will still be returned in the natural order of that list of posts returned. Note this parameter was introduced with Version 3.1 and replaced the deprecated caller_get_post.
  • caller_get_posts=1 – To exclude sticky posts being included at the beginning of posts returned, but the sticky post will still be returned in the natural order of that list of posts returned. Note that this argument is deprecated as of Version 3.1.

Source: WordPress.org

So if you are currently using custom templates with sticky posts and the caller_get_posts parameter, make sure you switch that to ignore_sticky_posts when you upgrade to WordPress 3.1!

Flickr photo by Dylan Cantwell.

Tags: , , , , , , , , , ,

  • Enno

    Thanks!

  • Mikkel Breum

    passing the ignore_sticky_posts=1 parameter to query_posts does ‘unstick’ any sticky posts and leave them in the normal post flow. It does however, fail to remove the sticky class from those posts, so if you have any css formatting going on for the sticky class, make sure to also remove the class.

  • http://www.virtualidstudios.com David

    Yup.  I know this is old, but for future readers, here’s the documentation:

    http://codex.wordpress.org/Class_Reference/WP_Query#Sticky_Post_Parameters