WordPress Sticky Post on home page

We can show posts based on only selected authors from wordpress users. For this we can use “query_posts” function. Just Goto Appearance –>  Editor –> select page Index.php and place the below code and see.

Sticky Post Parameters

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

  • array('post__in'=>get_option('sticky_posts')) – returns array of all sticky posts
  • 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.

To return just the first sticky post:

$sticky=get_option('sticky_posts') ;
query_posts('p=' . $sticky[0]);


$args = array(
	'posts_per_page' => 1,
	'post__in'  => get_option('sticky_posts'),
	'caller_get_posts' => 1

Note: the second method returns only the more recent sticky post; if there are not sticky posts, it returns the last post published.

To return just the first sticky post or nothing:

$sticky = get_option('sticky_posts');
$args = array(
	'posts_per_page' => 1,
	'post__in'  => $sticky,
	'caller_get_posts' => 1
if($sticky[0]) {
   // insert here your stuff...

To exclude all sticky posts from the query:

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

Return ALL posts with the category, but don’t show sticky posts at the top. The ‘sticky posts’ will still show in their natural position (e.g. by date):


Return posts with the category, but exclude sticky posts completely, and adhere to paging rules:

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
   'post__not_in' => $sticky,