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 ?
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);