njinok
njinok

Reputation: 65

PHP if isset issues

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

Answers (2)

Faizan Khattak
Faizan Khattak

Reputation: 882

Try this:

 if (!empty($term_data['death_date'])){

 }

OR this:

if ($term_data['death_date'] ?? null){

}

Upvotes: 1

Nipun
Nipun

Reputation: 157

Try this:

if (!empty($term_data['death_date'])){

}

Upvotes: 3

Related Questions