WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How is it possible to upgrade a post to make it sticky directly from code, not by admin area? Is it possible through a code like:

update_post_meta($post_id, $meta_key, $meta_value, $prev_value);

In this case, the $post_id is known, but the $meta_key?

Thank you in advance for your answers

share|improve this question
up vote 8 down vote accepted

The sticky posts are saved as an array of post IDs in the wp_options table. Hence,

$stickies = get_option( 'sticky_posts' );
$stickies[] = $post_id;
update_option( 'sticky_posts', $stickies );

will make the post in question sticky.


Even better, the core provides functions to stick and unstick posts (had to have 'em).

stick_post( $post_id );
unstick_post( $post_id );

--> See source on trac

share|improve this answer
Thank you very much for the answer – Avionicom Jun 3 '12 at 7:09

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.