publish_future_post not running
-
Hi, I’ve combed the forums and various results found via Google, but have yet to find a solution to an issue I have when trying to take action when a scheduled post is published. The code is pretty simple, so I hope I’m missing something obvious here.
The goal: when a sticky post is published, remove the sticky flag from all other posts, so there is only one published sticky post at a time. It’s important that this only executes at the time the new sticky post is published, not saved/scheduled, as there should always be one sticky post visible.
The code:
add_action('publish_post', 'custom_sticky_save_post'); add_action('publish_future_post', 'custom_sticky_save_post'); add_action( 'auto-draft_to_publish', 'custom_sticky_save_post' ); add_action( 'draft_to_publish', 'custom_sticky_save_post' ); add_action( 'future_to_publish', 'custom_sticky_save_post' ); add_action( 'new_to_publish', 'custom_sticky_save_post' ); function custom_sticky_save_post($post_id) { if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return; } $sticky = isset($_POST['sticky']) && $_POST['sticky'] == 'sticky'; if($sticky) { $sticky_posts = array($post_id); update_option('sticky_posts', $sticky_posts); } }This executes properly for sticky posts that are published immediately, but does nothing when a scheduled post publishes, so the previous sticky post(s) remains sticky. At present, this is all on my theme’s functions.php file, but once I resolve this, I will wrap it in a plugin for anyone to use. I think this should work solely with the first two add_actions, but I’ve included the others in an attempt to find something that works.
Thanks in advance!
The topic ‘publish_future_post not running’ is closed to new replies.