Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Is it possible to display the custom field/meta data content with some html?

Usually i would use the following to just display the content...

<?php echo get_post_meta($post->ID, '_cmb__description',true);?>

However, when there is actually meta content i want it to appear within some html, but i only want that html to appear when there is meta data to appear?

<?php echo get_post_meta($post->ID,<div class="box">. '_cmb__description'. </div>,true);?>

Is this possible? I'm not that up to scratch with it all, so wasn't sure if it was doable at all.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

Yes, just check if you got something back from the post meta:

$value = get_post_meta($post->ID, '_cmb__description',true);

if ( $value )
    echo "<div class='box'>$value</div>";
share|improve this answer
    
Perfect, thank you very much. –  user4630 Oct 26 '12 at 15:27
add comment

Your Answer

 
discard

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.