• Joshua

    (@cctvamerica)


    I’d like to put a function or action in our functions.php that automatically publishes ONE specific post at a specific times during the week, then returns it to draft status after a few hours. This would be reoccuring for that specific post. EX:

    Monday-Friday
    3pm: published — 10pm: draft

    Saturday/Sunday
    3pm: published — 830pm: draft

    I’ve been looking at WP-Cron, and Post Status Transition, but haven’t quite figured out making them work together. If anyone can point me in the right direction, I’d duly appreciate it. THANKS!

Viewing 3 replies - 1 through 3 (of 3 total)
  • You’re on the right track. I’m on mobile so I can’t provide code examples but it would look like so:

    Create an event to fire every 24 hours. 15m if you want precision but you’ll want to short circuit the handler if conditions aren’t met.

    Create the handler with this logic ( or a variation ):
    If – day of week = mon-fri
    And – time between 3pm & 10pm set published for draft posts
    Else – set draft for published posts

    Similar logic for weekend times. But it could go in the same handler. Depending on the amount of posts you have this can be heavy. But is definitely a quick solution.

    To set the status you’ll need a query to pull all draft posts by post status then update those if not empty. Opposite for published posts.

    For that look into get_posts or WP_Query.

    Thread Starter Joshua

    (@cctvamerica)

    Thanks Jerry. Good notes, but what I actually want to do is have ONE specific post go from draft to publish on a reoccurring schedule. Basically turning it on and off at specific times. Any thoughts. Thanks much!

    Same idea just won’t have to run a query. You really just need the time logic in place and then use wp_update_post.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Schedule a specific post status to change at regular times’ is closed to new replies.