I am using the hook publish_post
to run my code where I need the post meta of the just published post. But the post meta value I am looking for is somehow not available at this point of execution. On checking the wp_postmeta
table, I found that my meta key value hasn't been created yet. Also, I want this to work for a post published for the first time. Is there any other hook that can give me access to it?
function push_notification($post_id)
{
$ref_ids = get_post_meta($post_id,'ref_id');
if($ref_ids)
{
//my code goes here
}
}
add_action('publish_post','push_notification');
save_post
and check forpost_status
equal topublish
, i.eif ( 'publish' == $post->post_status ) ..etc
and if you only want to run this function on newly published posts, not re-published/updated posts you could look atwp_transition_post_status
and check for$old_status
against$new_status
get_post_meta($post_id,'ref_id')
returns nothing. Therefore, my code is never executed.save_post
. No post meta available. I should have mentioned before that I want this to work for a post published for the first time. Andsave_post
gives access to post meta only at updates.