Leave a Reply

1 comment

  1. 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.

    EDIT:

    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