0

I have a multiple checkbox type question (using Ultimate member) storing values as user meta.

The question basically asks the user what he wants, and according to what he wants, I would like my homepage to show different contents. Multiple values are possible.

My code is :

$user_id = get_current_user_id();
$single = true;
$key = 'your_needs';
$needs = get_user_meta( $user_id, $key, $single ); 

if ( !empty($needs) ) : 

foreach ($besoins as besoin) :

if ( $need = "Option A") {

    get_template_part('front/option-a'); 

}


if ( $need = "Option B") {

    get_template_part('front/option-b'); 

}

if ( $need = "Option C") {

    get_template_part('front/option-c'); 

}


if ($need = "Option D") { 

    get_template_part('front/option-d'); 

}

endforeach;

endif;

This is only working halfway. It does return the correct template part, one after another, but regardless of whether or not is is checked. However I would like for my code to load the template part ONLY if current option is checked.

Also, keep in mind that I want the user to be able to check different options (ie. B and D -> loads template parts B and D)

0

Classic case of = instead of ==, ie. you're assigning values in a conditional statement, which always resolves to true:

if ( $need == "Option A") {

    get_template_part('front/option-a'); 

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.