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);
2
  • 1
    How are you setting the baseSalary meta to begin with? Can you show the $post_args used? Aug 9, 2017 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. Aug 11, 2017 at 3:34

1 Answer 1

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.

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.