0

I am trying to get post meta after post is being inserted via code but its not working.

Post meta not showing:

$id = wp_insert_post( $post_args );
$zip=get_post_meta( $id,'baseSalary',true);
print_r($zip);

Below code is working:

$id = wp_insert_post( $post_args );
    $zip=get_the_title( $id);
    print_r($zip);
  • 1
    How are you setting the baseSalary meta to begin with? Can you show the $post_args used? – Jacob Peattie Aug 9 '17 at 12:29
  • Right. Show your $post_args. If you have used meta_input while register post type in $post_args then you'll get it. – maheshwaghmare Aug 11 '17 at 3:34
0

$id = wp_insert_post( $post_args );

$zip=get_post_meta( $id,'baseSalary',false);

print_r($zip);

write false rather than true if you want to get the array of values.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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