I want to return some post meta , but when i use the functions get_post_meta or get_post_custom the functions returns allways the values 1 for all the meta data, i tried several thinks but they returns the same value , i suspect that they returns boolean value. In the wp_postmeta table the meta_value is equal to 30.

  $build['time'] = get_post_meta($id, 'prep_time') ;  //retun 1
  $build['time'] = maybe_unserialize(get_post_meta($id, 'prep_time')) ;

Any Idea what is wrong ?


1 Answer 1


get_post_meta takes 3 params, not two:

get_post_meta( int $post_id, string $key = '', bool $single = false )

As you can see, the third param is false by default. It means, that if you don’t pass it, the function will return an array with all custom fields for that key.

If you have only one meta field with key prep_time, you’ll get:

Array( 0 => "30" )

On the other hand I’m pretty sure that’s not what you’re expecting, so you should pass true as the third param like so:

$build['time'] = get_post_meta($id, 'prep_time', true);

Your Answer

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

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