Reputation: 37
I am trying to get the submitted post meta on the post_updated action via the function get_post_meta().
However it only returns the old metadata, before I clicked the "Save" button. Probably because the new meta wasn't saved to the database yet.
Is there any way to get the new metadata inside the getMeta function below?
add_action('post_updated', 'getMeta', 10, 1);
function getMeta($post_id) {
if($post->post_status != 'trash'){
$meta = get_post_meta($post_id);
echo '<pre>'; print_r($meta); echo '</pre>';
}
}
Thanks!
Edit: I have to use the post_updated action for other operations, which aren't displayed in the above code example. So using an other action is unfortunately not an option :(
Upvotes: 3
Views: 1380
Reputation: 4228
You're hooking to wrong action, try something like
add_action('updated_postmeta', 'getMeta', 10, 4);
function getMeta($meta_id, $object_id, $meta_key, $meta_value)
{
if($post->post_status != 'trash')
{
// do you magic here
}
}
Upvotes: 1