1

I'm working on a plugin for wordpress that I would like to fire every time a custom post of the type 'job' is posted, published, edited, trashed, untrashed, etc. (basically whenever there is an update to that post type).

I'm having a bit of trouble finding the correct action hook to call. I have searched, and from my understanding I can't use for example (publish_post) because I am using a custom post type, so it should be something along the lines of (publish_job) or publish_post_job. However, those don't seem to work for me either, if I go in to the jobs category and publish a draft in the jobs category.

So, I guess I have two questions:

1) What is the correct action I should be using in the context of a custom post type.

2) a. Is there some sort of action that I can use to encompass all sorts of changes to the jobs category (ie: post editing, publishing, unpublishing, trash/untrash, etc). b. If not, how would I go about calling add_action for all of those possible actions.

Thank you!

2
  • 1
    transition_post_status does all in one May 11, 2015 at 15:52
  • My pleasure :-) May 11, 2015 at 16:33

1 Answer 1

0

As @Pieter said, you can use transition_post_status:

function wpse_187997_job_status( $new_status, $old_status, $post ) {
    if ( $post->post_type === 'job' && $new_status !== $old_status ) {
         // Post type "job" and status has changed
    }
}

add_action( 'transition_post_status', 'wpse_187997_job_status', 10, 3 );

Your Answer

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

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