This is the code:

if ($keys = get_post_custom_keys()) {
    foreach ((array) $keys as $key) {
        $keyt = trim($key);
        if (is_protected_meta($keyt, 'post')) {

        $values = array_map('trim', 
        $value = implode($values, ', ');
        echo " key : ".$key;
        echo " value : ".$value;

The Result:

keyyy : nova_price valueee : $9 

My question: Is there a specific Wordpress function to get the meta value $9 using meta key nova price?

I tried using this WP function:

echo" get_post_meta: "; get_post_meta(the_ID(), 'nova_price', true);

but the result is:

get_post_meta: 1872 

Any help would be greatly appreciated. Many Thanks.

  • 4
    Try using get_the_ID() instead of the_ID() in your get_post_meta(). the_ID() echoes in the post id directly, and hence the number 1872. So it should be get_post_meta( get_the_ID(), 'nove_price', true)
    – Kumar
    Jun 16 '18 at 4:10
  • Thanks, I did use get_the_ID() but it returned nothing link, which is weird.
    – Ray Macz
    Jun 16 '18 at 9:15
  • If I use the_ID() this was the result
    – Ray Macz
    Jun 16 '18 at 9:27
  • Try var_dump( get_theID() ); just before your get_post_meta(); call and check if it returns the correct post id.
    – Kumar
    Jun 18 '18 at 7:10

As the solution suggested in comments worked out for you, I'll just post that as answer over here.

You need to replace the_ID() function in your get_post_meta(the_ID(), 'nova_price', true); call.

Because the_ID() directly outputs the post ID which is then getting printed for you instead of the meta.

Right code would be: get_post_meta( get_the_ID(), 'nova_price', true) This should get you the value for nova_price for the given post.


Actually, it was really my stupid mistake. Somehow, I was too focused on get_post_meta(). Upon checking the WP code reference, I began to realize that it wasn't the wrapper's problem get_post_meta(), when this worked:

get_metadata('post', 1874, 'nova_price', true);

So the problem is this:

echo" get_post_meta: ";  get_post_meta(get_the_ID(), 'nova_price', true);

It should have been like this:

echo" get_post_meta: ". get_post_meta(get_the_ID(), 'nova_price', true);

A minor problem that I overlooked. At least now, I know the 2-functions in getting the value by meta key in WP. Again, many thanks for the effort & help.

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.