WordPress.org

Ready to get started?Download WordPress

Forums

How do I unsticky posts? (PHP code) (3 posts)

  1. musicmasteria
    Member
    Posted 4 years ago #

    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

  2. musicmasteria
    Member
    Posted 4 years ago #

    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

  3. musicmasteria
    Member
    Posted 4 years ago #

    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/

    Enjoy!

Topic Closed

This topic has been closed to new replies.

About this Topic