Reputation: 1
I want to trigger a function after the post is published, updated or Scheduled. I have used the save_post
hook which works great with the Post published and update. But not working with the scheduled post.
I have tried some of the WordPress hook but it doesn't work properly.
Upvotes: 0
Views: 449
Reputation: 101
If what you want to do is to trigger the function at the moment the post is published, because you manually published it or you scheduled its publication for any time later, then you can use the action hook transition_post_status
.
add_action( 'transition_post_status', 'my_custom_function', 10, 3 );
function my_custom_function( $new_status, $old_status, $post ) {
if ( 'publish' == $new_status ) {
// Do something...
}
}
Upvotes: 0
Reputation: 1
I think you should try the future_to_publish action for accomplish the task. It will help you.
function scheduled_post_published($object)
{
// whatever it is you need to do
}
add_action('future_to_publish', 'scheduled_post_published');
Upvotes: 0