Custom Fields value not displaying
-
I’m using this little snippet to (hopefully) display ‘Location’ on single.php of my theme.
<?php $location = get_post_meta( get_the_ID(), ‘location’, true ); // check if the custom field has a value if( ! empty( $location ) ) { echo '<div class="location">'; echo ($location > 0) ? $location : ''; echo '</div>'; } ?>
However, this displays absolutely nothing.
I have luck with getting this to display…
<div class="location"><?php echo get_post_meta($post->ID, 'location', true); ?></div>
… but it is on full display, even if the custom field has no value.I’m trying to have my div (along with the custom field content) display only when the field value has content, as I do not necessarily want to enable this on every post.
Please help!
Many thanks!
Ashley
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Custom Fields value not displaying’ is closed to new replies.