I need to do some actions only on newly published posts that requires post metadata.
I've tried many different hooks, but they all also trigger for other "events" like updating post, or if they trigger only on publish, metadata is empty or just has _edit_lock value inside.
auto-draft_to_publish hook triggers when I need it, but there is no post meta
add_action( 'auto-draft_to_publish', 'wpse120996_specific_post_status_transition' ); function wpse120996_specific_post_status_transition($post) { if ($post->post_type != 'poruke') { return; } $post_meta = get_post_meta($post->ID); echo "<pre>"; die(var_dump( $get_post_meta )); echo "</pre>"; }transition_post_status works with the right status checks, but there is no post meta as well
'publish' === $new_status && 'publish' !== $old_status // right time,no post metapublish_post it seems that this one doesn't even trigger for some reason
add_action( 'publish_post', 'myfunction' ); function myfunction($post) { echo "<pre>"; die(var_dump( 'PUBLISHED?' )); // this dump is nowhere to be found, I looked in network tab in debugger echo "</pre>"; }save_post this one triggers as soon as "Add New" is pressed in a sidebar
I'm having a lot of problem with this and I have hard time beliving that something so "basic" would not be a feature in wordpress, but I didn't find anything helpful in my search so far.
Thanks in advance.
'publish_post'hook is deprecated, see adambrown.info/p/wp_hooks/hook/publish_post According to the link,publish_postonly works when something of post-type: post is changed to publish status. Also, I am surpriseddie(var_dump('anything'))does anything for you, becausevar_dump()doesn't return anything. I would write var_dump('anything'); die(); but this is detail. It seems you have ran into a hard problem, I'm still working on it. - Snuwerd