$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>post meta - meta_post_meta return value 1|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

post meta - meta_post_meta return value 1

matteradmin12PV0评论

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

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far