Reputation: 65
I only want to echo output only when 'death_date' has a value. This is my code:
<?php if (isset($term_data['death_date'])): ?>
<li>
<label><?php echo esc_html__('Deceased on:'); ?></label>
<span><?php echo esc_attr($term_data['death_date']); ?></span>
</li>
<?php endif; ?>
However this code still outputs 'Deceased on:' whether 'death_date' has a value or not. What am i doing wrong here? Any help would be appreciated. Thank you.
Upvotes: 0
Views: 84
Reputation: 882
Try this:
if (!empty($term_data['death_date'])){
}
OR this:
if ($term_data['death_date'] ?? null){
}
Upvotes: 1