WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using, for example: <?php echo get_post_meta($post->ID, "Pricing_Land_Only", true); ?> but need to know how to implement the 'else' function to display 'Nothing found' if I didn't type anything in that field.

The reason being is for different pricing fields that I have and while not all pages use the same fields, most would. Thanks!

share|improve this question

You could do it like this:

// store post meta in a variable and use that so you aren't pulling the post meta data twice
$landPricing = get_post_meta($post->ID, "Pricing_Land_Only", true)
    echo $landPricing;
    echo "Sorry, nothing was found.";
share|improve this answer
why not just store everything in a variable, then check the variable instead of calling get_post_meta twice? – Brian Fegter Oct 11 '12 at 22:56
For some reason, WP didn't like me doing that, or I added it incorrectly: Fatal error: Can't use function return value in write context in /home/toasterd/public_html/bctderezzed.co/wp-content/themes/trece/tour-template.‌​php on line 83 when entered as <?php if(!empty(get_post_meta($post->ID, "Pricing_Land_Only", true))) { echo get_post_meta($post->ID, "Pricing_Land_Only", true); } else { echo "TBD or not applicable"; } ?> – toasterdroid Oct 11 '12 at 22:58
+1 for the edit. – Brian Fegter Oct 11 '12 at 23:30
Thanks @BrianFegter, I definitely wasn't thinking very clearly when I wrote that out. toasterdroid please see my updated answer, as I think what I originally showed you would break as you have seen. – Ben Oct 11 '12 at 23:46

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.