我有一个多复选框类型的问题(使用最终成员)将值存储为用户元。
这个问题基本上是问用户他想要什么,根据他想要什么,我希望我的主页显示不同的内容。可以有多个值。
我的代码是:
$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;
这只是半途而废。它会一个接一个地返回正确的模板部分,但不管是否选中。但是,我希望我的代码仅在选中当前选项时加载模板部分。
另外,请记住,我希望用户能够检查不同的选项(即B和D->加载模板B和D部分)