Answer the question
In order to leave comments, you need to log in
How to correctly check the presence of an arbitrary field for block output in a VI?
Tell me, who knows .. If there is an arbitrary field, it is necessary to display a block with text ... where the text is taken from this arbitrary field .. In this example, an arbitrary field named text1 ... But this construction does not work ... Tell me where the error is Or maybe I'm doing something completely wrong?
<?php if (get_post_meta($post->ID, 'text1', true) !== '') {?>
<div class="text">
<?php echo (get_post_meta($post->ID, 'text1', true)); ?></div>
<?php}?>
<?php if (get_post_meta($post->ID, 'text1', true) !== '')
{echo "<div class="text">".get_post_meta($post->ID, 'text1', true)."</div>"; }?>
Answer the question
In order to leave comments, you need to log in
Like this:
if (isset(get_post_meta($post->ID, 'text1', true))) {
//your code
}
if (get_post_meta($post->ID, 'text1', true)) {
//your code
}
if ($text = get_post_meta($post->ID, 'text1', true)) {
echo '<div class="text">'.$text.'</div>';
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question