Answer the question
In order to leave comments, you need to log in
How to check if there is data in a field?
Good afternoon!
How to check if a field is empty in a function:
<?php echo get_post_meta($post->ID, 'value', true); ?>
if isset ($value) {
<p>
<?php echo get_post_meta($post->ID, 'value', true); ?>
</p>
}
Answer the question
In order to leave comments, you need to log in
I understand that you need to check what the get_post_meta() function returns?
if so, then check
But this will only work when the get_post_meta() function returns NULL or FALSE. If it can return a space, then it's better to check the length of the string.
If the field exists and the value is not empty:
if( ! empty( get_post_meta( $post->ID, 'value', true ) ) ) {
echo get_post_meta($post->ID, 'value', true);
}
if( ! empty( trim( get_post_meta( $post->ID, 'value', true ) ) ) ) {
echo get_post_meta($post->ID, 'value', true);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question