post meta - meta_post_meta return value 1

admin2025-06-02  1

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 ?

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 ?

Share Improve this question asked Mar 9, 2019 at 10:00 alpha.romeoalpha.romeo 491 gold badge1 silver badge5 bronze badges 0
Add a comment  | 

1 Answer 1

Reset to default 3

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);
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748827054a314050.html

最新回复(0)