• 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

    (@musicmasteria)

    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

    (@musicmasteria)

    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:
    https://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.