2

I have a function to run every time a post is published or updated in anyway. Right now I am doing

function myFunction(){
   //Do Something
}    
add_filter('publish_post','myFunction');
add_filter('wp_update_post','myFunction');

Now, when I do this the function is getting called on when I publish a post or make any changes to the Status: Draft/Pending Review (as shown in the attached image), the function is not called. What function to hook to run my function on Status change?

enter image description here

Got it to work. Answer below

3
  • This is a filter of data, it does not alter the data saved. Do you wish to alter the saved data of the post? Commented May 28, 2016 at 8:29
  • I got the solution, I wanted to run a function whenever post status changed. I will update the solution so that it can help others
    – PRYM
    Commented May 28, 2016 at 8:30
  • Awesome! I wanted to be sure that your wish was to filter data, rather than change it. Commented May 28, 2016 at 8:32

1 Answer 1

3

What I was looking for was transition_post_status. The documentation can be found here.

What I did was to add one more filter add_filter('transition_post_status','myFunction');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.