Sign up ×
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 check if a custom field exists for a given post within the loop? For example, I'm using functions like get_post_meta($post->ID, 'Company', true); preceded by a <h4> tag, but I'd like to check to make sure that there is a value for the custom field "Company" before writing the <h4>. Is this possible?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

The WP get_ methods are here to retrieve data, not to display them. You can easily check the var - containing the data - before adding your head tags:

$my_post_meta = get_post_meta($post->ID, 'Company', true);
if ( ! empty ( $my_post_meta ) )
    echo '<h4>'.$my_post_meta.'</h4>';
share|improve this answer
This worked perfectly, thanks! – daysrunaway Jul 10 '11 at 4:15

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.