I’m trying to use the add_action() hook to run a custom function, but am struggling with the post status.
I originally tried using:
add_action('pending_to_publish_portfolio', 'my_function');
(portfolio being my custom post type).
This didn’t work, so i posted in the official WordPress Support forum for some help.
I was given the following code to get the right transition status’
function bj_test($new, $old) {
print_r($old . '_to_' . $new);
echo '<br>';
print_r($old . '_' . $new);
die();
}
add_action('transition_post_status', 'bj_test', 10, 2);
This gives me 2x status’:
new_to_inherit
new_inherit
I’ve looked at the inherit status and the codex simply states it’s used for post revisions. Which makes sense as i’m changing from a pending post to a published post.
My problem is, i just don’t know how to use this information now.
All i’m trying to do is trigger an event when i changed a post from pending to published.
According to all the online tutorials i can find it should be as easy as my very first attempt (posted above), but that just doesn’t work.
Has something changed recently in the way post transitions are handled so all these tutorials are out of date?
It’s probably really simple for somebody who knows what they’re doing, but i’m very new to WP and am running out of options 🙁
any help appreciated.