When I save my post (custom post type: project) I want to get the meta data for a specific key that I just inserted. Based on the value of that key I insert a product in WooCommerce.

What happens is that I get the past value for the meta key, instead of the current/new one. Here's the code I use:

function shortened($post_id){

   $key_verkoop_ja_nee = "kaart_verkoop";
   //$value_verkoop_ja_nee = get_post_meta($post_id, $key_verkoop_ja_nee, TRUE);
   //$value_verkoop_ja_nee = $GLOBALS["wp_object_cache"]->cache["post_meta"][$post_id][$key_verkoop_ja_nee][0];
   //$value_verkoop_ja_nee = $_REQUEST[$key_verkoop_ja_nee];
   $value_verkoop_ja_nee = $_POST[$key_verkoop_ja_nee];

   if($value_verkoop_ja_nee == "Yes"){
       //Do a lot of stuf

add_action( 'save_post_project', 'shortened', 999 );

$_POST and $_REQUEST don't return any value at all, get_post_meta and the $GLOBALS return the past value. I tried edit_post instead of save_post, in/decreased the importance (999) and used global $post in the function. Nothing works.

Any idea how the get the new inserted meta value?

Thanks a lot!

1 Answer 1


Use add_action( 'save_post', 'shortend', 999);

and put this in your function as first.

if ( 'project' != $_POST['post_type'] )
    return $post_id;

If this doesn't work then you should echo $_POST; and see if kaart_verkoop is part of the array.

  • Thanks for your answer Augus. I already tried this and unfortunately didn't work. However, good idea to check all $_POSTs (should have figured that out myself...). I used Advanced Custom Fields to create meta boxes and instead of pushing the meta data into meta data, ACF uses an array of "fields". There I could find the keys and the values. So thanks! Jul 17, 2014 at 14:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.