简体   繁体   English

具有OR条件的多个WordPress类别IF不起作用

[英]Multiple wordpress category IF with OR conditional not working

I wanted to select one of 3 or more conditional statement, but I can't get it work as intended. 我想从3个或多个条件语句中选择一个,但无法按预期运行。 It showing "Game title: 1". 它显示“游戏标题:1”。 Here is the code I'm using: 这是我正在使用的代码:

<?php echo "<strong>Game Title: </strong>";
    if( $info = get_field('pcgame_name') || get_field('psppublisher') || get_field('ps3game_name') ) { ?>
        <?php echo $info;?>
    <?php } ?>

A single "=" is an assignment ie making $info = 1 (because one or more of the functions is returning True/1). 单个“ =”是一个赋值,即使$ info = 1(因为一个或多个函数返回True / 1)。 You use "==" to check for equality so you probably want: 您使用“ ==”来检查是否相等,因此您可能需要:

<?php echo "<strong>Game Title: </strong>";
if( $info == get_field('pcgame_name') || $info == get_field('psppublisher') || $info == get_field('ps3game_name') ) { ?>
    <?php echo $info;?>
<?php } ?>

Edit: If you are not trying to compare a value with $info but instead trying to echo the value of the first non-empty ACF field then try this: 编辑:如果您不尝试与$ info比较值,而是尝试回显第一个非空ACF字段的值,请尝试以下操作:

<?php echo "<strong>Game Title: </strong>";
   $info =  get_field('pcgame_name');
   if (empty($info)) $info = get_field('psppublisher');
   if (empty($info)) $info = get_field('ps3game_name');
   echo $info;
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM