Hi,
I am trying to include a custom field value without displaying the key. Previously I would have used a shortcode plugin to do this, but echoing a do_shortcore seems a little hacky to me. Is there a better way?
Hi,
I am trying to include a custom field value without displaying the key. Previously I would have used a shortcode plugin to do this, but echoing a do_shortcore seems a little hacky to me. Is there a better way?
I'm not sure I really understand this function.
Lets say I only have one key called descriptions, I think the php should look like this:
<?php $key_description_value = get_post_meta($post->ID, 'Description', true); echo $key_description_value;?>
or
<?php $key_description_value = get_post_meta($post->ID=$post_id, 'Description', true); echo $key_description_value;?>
but I get nothing...
<?php $key_description_value = get_post_meta($post->ID, 'Description', true); echo $key_description_value;?>
Will work, providing it's in the loop (so it has a post ID) and the custom field exists for that post.
You could narrow down the problem by IF/ELSE'ing the field value check. You could also check the post ID is valid.
<?php if(!$post->ID) echo 'post ID doesn\'t exist'; ?>
<?php $key_description_value = get_post_meta($post->ID, 'Description', true); ?>
<?php if(!$key_description_value) { echo 'nothing found'; } else { echo $key_description_value; }?>This topic has been closed to new replies.