简体   繁体   中英

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. It showing "Game title: 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). 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:

<?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;
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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