Title: How do I unsticky posts? (PHP code)
Last modified: August 19, 2016

---

# How do I unsticky posts? (PHP code)

 *  [musicmasteria](https://wordpress.org/support/users/musicmasteria/)
 * (@musicmasteria)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/how-do-i-unsticky-posts-php-code/)
 * Hi,
 * I’m trying to make a php script that I can run to unsticky all posts that have
   been stickied for 3 days. I have the first part of the code done. It does:
 * 1. Gets current date (in unix)
    2. query_posts’s all sticky posts into an array
   3. Finds the ‘post_date’ of all stick posts + converts them to Unix format 4.
   Compares (post_date) to (current date – 3 days) 5. Creates array of post ID’s
   that need to be un-stickied — And now I’m stuck..
 * What’s the code to un-sticky a post by ID?
 * Thanks,
    Musicmasteria

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Thread Starter [musicmasteria](https://wordpress.org/support/users/musicmasteria/)
 * (@musicmasteria)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/how-do-i-unsticky-posts-php-code/#post-1174692)
 * For those looking for this as well, here is what I found:
 * `update_option('sticky_posts', $Array_of_IDs_to_stay_stickied);`
 * The array looks like:
 *     ```
       Array
       (
           [0] => 1111
           [1] => 1112
           [2] => 1113
       )
       ```
   
 * Where 1111, 1112, & 1113 are the post ID’s of the sticky posts you want to keep.
 * Not exactly what I was looking for but it will do.
 * This will return an array will all existing sticky posts ID’s:
    `get_option('
   sticky_posts');`
 * Enjoy
 *  Thread Starter [musicmasteria](https://wordpress.org/support/users/musicmasteria/)
 * (@musicmasteria)
 * [16 years, 5 months ago](https://wordpress.org/support/topic/how-do-i-unsticky-posts-php-code/#post-1174958)
 * For those who are looking for a solution to the problem i had before, I have 
   made a plugin that does exactly what I was asking for.
 * You can find it here:
    [http://takeouttactics.com/projects/wordpress/plugins/cron-unsticky-posts/](http://takeouttactics.com/projects/wordpress/plugins/cron-unsticky-posts/)
 * Enjoy!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘How do I unsticky posts? (PHP code)’ is closed to new replies.

## Tags

 * [Coding](https://wordpress.org/support/topic-tag/coding/)
 * [php](https://wordpress.org/support/topic-tag/php/)
 * [post_date](https://wordpress.org/support/topic-tag/post_date/)
 * [Sticky posts](https://wordpress.org/support/topic-tag/sticky-posts/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 1 participant
 * Last reply from: [musicmasteria](https://wordpress.org/support/users/musicmasteria/)
 * Last activity: [16 years, 5 months ago](https://wordpress.org/support/topic/how-do-i-unsticky-posts-php-code/#post-1174958)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
