Enable function when publishing wordpress scheduled post

Asked

Viewed 126 times

0

Ola, have a wordpress site that I schedule posts. What I want is that after it is published, activate a function that does something.

I saw that you can put functions.php but I don’t know what I call this function after scheduled posts are published.

For example I have a post scheduled for 12:00, another for 13:00, another for 14:00. Every time a scheduled post is published this function is called.

How do I do that?

NOTE: I don’t want to use plugins.

Thank you!

1 answer

1


There are some alternatives to this, which usually involve intercepting the change of status of the post and running its code.

You can choose which of these actions fit best with what you want to do:

// Se o código deve rodar apenas quando um post agendado é publicado
add_action(  'publish_future_post',  'publica_post' );
function publica_post( $post_id ) { // Seu código aqui
}

// Se o código deve rodar sempre que houver uma transição de status
// por exemplo, de rascunho para agendado, ou de rascunho para publicado
add_action(  'transition_post_status',  'publica_post', 10, 3 );
function publica_post( $novo_status, $antigo_status, $post ) { // Seu código aqui
}

// Se o código deve rodar sempre que um post for publicado
add_action(  'publish_post',  'publica_post', 10, 2 );
function publica_post( $post_id, $post ) { // Seu código aqui
}

publish_future_post

transition_post_status

{new_status}_{$post->post_type}

  • Fantastic, there you go!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.