如果 ACF 字段不存在,是否可以回显某些内容?

我在 WordPress 中有一个单选按钮 ACF 字段,有两个按钮“svarvning”和另一个“frasning”,但我的 acf 字段也有一个“自定义”按钮

http://img.mukewang.com/6290914d0001682c02590088.jpg

如果'svarvning' 或 'frasning' 都不是true ,我想回显 'custom field' 的值。


这可能吗? 如果它是真的,我让它工作


<?php 

    if (get_field('kurstyp') !== 'svarvning' . 'frasning') { 

       echo "It's not equal!" 

    } else {

       die;

    }

?>

谢谢!!


大话西游666
浏览 170回答 2
2回答

呼如林

我认为您只需要修复条件检查,就目前而言,它将您的选项连接到一个不存在的选项中。<?php&nbsp;&nbsp; &nbsp; if (get_field('kurstyp') !== 'svarvning' && get_field('kurstyp') !== 'frasning') {&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;echo "It's not equal!"&nbsp;&nbsp; &nbsp; } else {&nbsp; &nbsp; &nbsp; &nbsp;die;&nbsp; &nbsp; }?>如果您有大量值要比较,您还可以检查值是否在可能性列表中,如下所示:&nbsp; &nbsp; $array=array('frasning', 'svarvning', 'etc');&nbsp; &nbsp; if (in_array(get_field('kurstyp'),$array))&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; echo 'Value found';&nbsp; &nbsp; } else {&nbsp; &nbsp; &nbsp; echo 'Not found';&nbsp; &nbsp; }

一只甜甜圈

试试这个条件。if( get_field('kurstyp') == 'svarvning' || get_field('kurstyp') == 'frasning' ){&nbsp; &nbsp; // Choice Value} else {&nbsp; &nbsp; // Button value}
打开App,查看更多内容
随时随地看视频慕课网APP