Gauri Padbidri
Gauri Padbidri

Reputation: 411

Wordpress plugin to do something on post publish

I am new to Wordpress. I am writing a custom plugin which will eventually take the Post Title Post URL and Post Content of the NEWLY PUBLISHED POST and store it in some other store as well in the background. I am using "publish_post" action for the same. However, I don't think it gets invoked.

I have a few queries around it :

  1. Which is the API Action / Filter that will help me achieve the above problem statement ?

  2. Is it best to use Actions OR Filters ?

  3. How do I identify whether the action was registered ?

  4. How do I identify if the action was INVOKED ? I tried putting an echo statement but it does not seem to display. Also on "Publish" Click, the icon next to the button keeps going round to denote that the Publish is in progress. I am confused.

Kindly help. Thanks !

Upvotes: 0

Views: 413

Answers (1)

Ionuț Staicu
Ionuț Staicu

Reputation: 22164

You can add a save_post hook:

add_action( 'save_post', 'save');
function save( $id ){
  if( get_post_status( $id ) == 'publish' ) {

  }
}

For action vs filter question: these are not something that you can interchange; they are different beasts. Think this way: with a filter you can alter a value (so you need to return a value), with an action you can't.

Upvotes: 1

Related Questions