0

我一直在弄清楚如何根据自定义字段中的输入来显示不同的数据。

我在注册表单中有单选按钮作为我的输入字段,有 3 个选项。X、Y、Z。

它们保存在名为 member_status 的自定义字段中,保存为 user_meta

我的代码工作是这样的……但我想不通!

global $current_user;

get_currentuserinfo();

$userID = $current_user->ID;

$memberstatus = get_user_meta($userID,'member_status',true);

If $memberstatus = X {

// do something here if X

} elseif $memberstatus = Y {

// do something here if Y

} elseif  $memberstatus = Z {

// do something here if Z

问题是:.......

我不知道如何正确构造 IF 语句,这只是上面的猜测......

4

2 回答 2

2

如果您真的将其保存为元数据,member_status则:

if($memberstatus == 'X'){
    // do something here if X
} elseif ($memberstatus == 'Y'){
    // do something here if Y
} elseif ($memberstatus == 'Z'){
    // do something here if Z
}
于 2012-10-01T06:52:57.867 回答
0

您应该使用==而不是=进行比较。

==是比较运算符,=是赋值运算符。

也不要忘记将布尔条件括在括号中()

if($memberstatus == X){

}
elseif($memberstatus == Y){

}
// and so on
于 2012-10-01T06:55:29.970 回答