I need to check the value of a post status before is changed during a post update or even bulk update. And then depending on that value, adjust other values of the post


Lets say I have a custom post status

  • status-one
  • status-two
  • status-three

I have post "A" who's status is status-one. So when I update this post to another status, status-two, I need to check if my old status was status-one or not?

I know this sounds a bit confusing. Please do let me know if there is any way I can clarify it.

  • So you need to update the post if its status is status-one otherwise it will not be updated, right ? – CodeMascot Jan 2 '17 at 9:46
  • @the_dramatist , I need the to run a function if post status has been switched form status-one to status-two. However, if the post status has been changed from status-three to status-one, I don't need to run that function – bagpipper Jan 2 '17 at 10:06
  • I'm not clear, so you just need to know the previous status only ? – CodeMascot Jan 2 '17 at 10:09
  • @the_dramatist Yes – bagpipper Jan 2 '17 at 10:37

There is a hook called transition_post_status which runs at every transition. You have both the old and new status available inside the hook.

  • Thank you @cjbj. This is exactly what I was looking for :) – bagpipper Jan 2 '17 at 11:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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