Calling a Custom Field Outside the Loop & Modifying
-
Howdy –
I have hit an inpass in the development in one of my client’s sites. I have implemented the “Custom Field Template” and can call custom fields both inside and outside of the WordPress loop.
The issue I’m having is in trying to figure out how to conditionally add additional text, appended to the called field but ONLY if there is information available in that custom field.
For example, if I have a custom field called keyed “numberbedrooms” with a value of “3”, how could I code the call to display the value followed by the word “bedrooms” but if the field has no value in it, it displays nothing. The code I am using to call the custom field outside the loop is as follows:
<span class="meta"> <?php global $wp_query; $postid = $wp_query->post->ID; echo get_post_meta($postid, 'numberbedrooms', true); ?></span>
I hope this makes sense, I’d be happy to clarify if not.
- The topic ‘Calling a Custom Field Outside the Loop & Modifying’ is closed to new replies.