1

I am trying to display the value of a Meta field on single.php. The Meta Key is 'current_rank'.

I tried...

<?php echo get_post_meta( get_the_ID(), 'current_rank', true);  ?>

This code does not output anything, not even an error. Any suggestions?

1
  • Are you running that in The Loop? Are you certain a value is stored in 'current_rank' for that specific post?
    – Christine Cooper
    Commented Sep 8, 2015 at 23:30

1 Answer 1

4

You're very likely running that outside of the loop.

To confirm, try the following:

$post_id = get_the_ID();

$current_rank = get_post_meta( $post_id, 'current_rank', true);

echo 'Post ID is: ' . $post_id;
echo '<br> Current Rank is: ' . $current_rank;

Are you getting post ID printed on the page? Is the current rank showing empty? Then the current_rank meta value for this post is definitely empty.

2
  • Figured it out. I the meta key was _current_rank not current_rank. Commented Sep 8, 2015 at 23:35
  • Outstanding... ;)
    – Christine Cooper
    Commented Sep 8, 2015 at 23:35

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.