I want to fire a function when a new post (cpt) is published.
function my_publish( $new_status, $old_status, $post ) {
if ( $new_status == 'publish' && 'publish' !== $old_status ) {
// do s.th.
}
debug_to_console( $post );
}
add_action( 'transition_post_status', 'my_publish', 10, 3 );
So when I hit the "Add New" button, the function is fired and I get my console log with the $post
content. And that's it.
The function than never fires again. Neither when I publish the post nor when a post is updated or the status of a post is changed.
I also tried the common other hooks like:
add_action('future_to_publish', 'my_publish');
add_action('new_to_publish', 'my_publish');
add_action('draft_to_publish' ,'my_publish');
add_action('auto-draft_to_publish' ,'my_publish');
those never did anything.
I did a lot of research the last days and tried a lot of different solutions but nothing helped to get me over this... any Ideas?
post
orpage
post types, in order to narrow down the source of your problem. If your custom post type does not usewp_insert_post()
to create or modify posts the hooks will not be fired.my_publish
only fires, when the"Add New"
button is clicked, doesn't matter which post-type.debug_to_console( $post );
caused the problem. This was echoing a<script>
tag....