【问题标题】:If Custom Field is Specific Value then do Something...(Radio Buttons)如果自定义字段是特定值然后做某事...(单选按钮)
【发布时间】:2012-09-22 00:43:14
【问题描述】:

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

我在注册表单中有单选按钮作为我的输入字段,有 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语句,这只是上面的猜测......

【问题讨论】:

  • 问题是……?
  • 所以我的代码不起作用.....我不知道如何编写 IF 语句来检查状态是 X、Y 还是 Z

标签: php wordpress if-statement radio-button conditional


【解决方案1】:

如果你真的用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
}

【讨论】:

    【解决方案2】:

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

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

    别忘了将布尔条件用括号括起来 ()

    if($memberstatus == X){
    
    }
    elseif($memberstatus == Y){
    
    }
    // and so on
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-07
      • 1970-01-01
      • 1970-01-01
      • 2021-02-23
      相关资源
      最近更新 更多