yarek
yarek

Reputation: 12034

worpdress: how to call a function when a scheduled post is published?

I am using wordpress.

I need to run a function (send a email) when a scheduled post is automatically posted.

What hook/function should I use ?

Upvotes: 1

Views: 1650

Answers (2)

Odyno
Odyno

Reputation: 51

I think you need to use the hook transition_post_status, from the documentation:

transition_post_status is a generic action that is called every time a post changes status.

And on https://wordpress.stackexchange.com/a/100657 I found piece of code that can you use as inspiration.

Upvotes: 0

Igor Yavych
Igor Yavych

Reputation: 4244

Use post status transition hooks

function scheduled_post_published($object) 
{
    // whatever it is you need to do
}
add_action('future_to_publish', 'scheduled_post_published');

Upvotes: 3

Related Questions