【问题标题】:ACF True/False Field, Only Run Code When Set To TrueACF True/False 字段,仅在设置为 True 时运行代码
【发布时间】:2019-08-11 06:22:30
【问题描述】:

我正在使用 ACF 谷歌地图向客户指示招标简报地点。

我正在使用 ACF True/False 字段,并且希望仅当该字段设置为 TRUE 时才显示 Google 地图地址链接。

<span class="font-weight-bold">
    <b>Compulsory Briefing:</b>
</span>

<?php the_field('compulsory_briefing') ?><br/>
<span class="font-weight-bold">
    <b>Address [Google Maps] <a class="directions" target="_blank" href="https://www.google.com/maps?saddr=My+Location&daddr=<?php $location = the_field('briefing_address'); echo $location['lat'] . ',' . $location['lng']; ?>"> <?php _e(' Get Directions','roots'); ?>
</a>

【问题讨论】:

    标签: google-maps advanced-custom-fields


    【解决方案1】:

    您需要将按钮包装在 if 语句中,以检查该值是否设置为 true 或 false:

    <span class="font-weight-bold">
        <b>Compulsory Briefing:</b>
    </span>
    
    <?php if( get_field('compulsory_briefing') ): ?>
        <span class="font-weight-bold">
            <b>Address [Google Maps] <a class="directions" target="_blank" href="https://www.google.com/maps?saddr=My+Location&daddr=<?php $location = the_field('briefing_address'); echo $location['lat'] . ',' . $location['lng']; ?>"> <?php _e(' Get Directions','roots'); ?></a>
        </span>
    <?php endif;?>
    

    如果您的 True/False 字段是“compulsory_briefing”,则更改它不是这种情况。

    有关 ACF Click Here 中 True/False 字段的更多信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-05
      • 1970-01-01
      • 1970-01-01
      • 2020-12-10
      • 2012-04-10
      • 2020-06-23
      相关资源
      最近更新 更多