Hide text if one custom field out of two is empty

I am calling my custom fields into my page template like this:

the team donated
<!– display funds raised –>
<?php $givingback_details_funds = get_post_meta($post->ID,’givingback_details_funds’, true); if ($givingback_details_funds == ”) { ?>
<!– display nothing if there is no entry for funds raised –>
<?php } else { ?>
<!– display this if there is another entry –>
<?php echo get_post_meta($post->ID, ‘givingback_details_funds’, true); ?>
<?php } ?>
<!– display days donated –>
<?php $givingback_details_days = get_post_meta($post->ID, ‘givingback_details_days’, true); if ($givingback_details_days == ”) { ?>
<!– display nothing if there is no entry for days donated –>
<?php } elseif ( isset($givingback_details_days) && $givingback_details_days == “1” ) { ?>
<!– display this if entry for day is ‘1’ –>
one working day
<?php } else { ?>
<!– display this if there is another entry –>
<?php echo $givingback_details_days ?> working days
<?php } ?>

This displays great if the post has only one value. Example: “the team donated £300” or “the team donated one working day”.

But I can’t figure out how to get the word “and” to appear between the two values. Example: “the team donated £300 and one working day” instead of “the team donated £300 one working day”.

Read more here:: Hide text if one custom field out of two is empty

Leave a Reply

Your email address will not be published. Required fields are marked *