jeudi 8 mars 2018

Add if-statement for a particular value to php array

I’ve got the following answer from a question I posted in WordPress Stack Exchange, but how do I add elseif (if-statement) for a particular value? For example, they might enter "£0", in which case I'll want to display nothing.

$giving_back = array();

$givingback_details_funds = get_post_meta( $post->ID,'givingback_details_funds', true );

if ( $givingback_details_funds ) {
$giving_back[] = $givingback_details_funds;
}

$givingback_details_days = get_post_meta( $post->ID, 'givingback_details_days', true );

if ( $givingback_details_days ) {
$giving_back[] = _n( 'one working day', $givingback_details_days. ' working days', $givingback_details_days );
}

if ( ! empty( $giving_back ) ) {
echo 'the team donated' . implode( ' and ', $giving_back );
}

Aucun commentaire:

Enregistrer un commentaire