add_action on inherit post status

I’m running into this same issue in some code I’m developing.

In your case though tree is a better hook as you only want to hook posts that are moving to ‘publish’

You need to hook your function into all of the possible {status}_to_publish hooks like this:

add_action('new_to_publish', 'my_function');
add_action('draft_to_publish', 'my_function');
add_action('auto-draft_to_publish', 'my_function');
add_action('pending_to_publish', 'my_function');
add_action('future_to_publish', 'my_function');
add_action('private_to_publish', 'my_function');

You found even pass the initial statues is using a foreach loop using the first part of the hook names from an array.

Leave a Comment