【问题标题】:Wordpress Advanced Custom Fields if statmentWordpress 高级自定义字段 if 语句
【发布时间】:2015-09-27 21:08:20
【问题描述】:

我似乎无法只显示我请求的内容。我在我的 Wordpress 网站上使用Advanced Custom Fields (ACF) 插件,并使用带有“部门\职位”的多选字段的中继器字段。

使用下面的代码,我希望只显示值等于我选择的值的内容。也许我看错了,但内容显示 strpos 是否为真。

<?php if (get_field('policy_links') ): ?>
   <center><h3><a name="All"></a>All Employees</h3></center>
    <hr>
    <ul class="bullets">
        <?php while (has_sub_field('policy_links')) : ?>
            <?php $jobtype = get_sub_field('who_is_this_for'); ?>
            <?php if (strpos ($jobtype, 'ma') !== false) { ?>                    
                <li><a href="<?php the_sub_field('link_to_the_document'); ?>">
                 <?php the_sub_field('display_name'); ?></a><span> -  <small>   
                 <?php the_sub_field('link_notes'); ?></small></span>
                 <?php the_sub_field('who_is_this_for'); ?></li>
            <?php } else { ?><p>fail </p>
            <?php }; // end of the loop. ?>
        <?php endwhile; // end of the loop. ?>
    </ul>
            <?php endif; ?>

【问题讨论】:

  • 请提供一个名字的例子,突出那些应该让你的if声明是真的。

标签: php wordpress advanced-custom-fields


【解决方案1】:

你的 if 语句应该是这样的:

&lt;?php if(get_sub_field('who_is_this_for') == 'strpos') { ?&gt;&lt;?php }?&gt;

其中“strpos”是您选择的值(如果我遵循正确的话)。

实际查看您的字段可能会有所帮助。

【讨论】:

    【解决方案2】:

    我在正确的轨道上。从选择多个值时,它会拒绝将ACF转换为数组。我对变量执行了一次内爆,然后使用转换后的字符串执行了验证。 感谢您的帮助

    【讨论】:

      猜你喜欢
      • 2012-01-17
      • 2014-03-10
      • 1970-01-01
      • 2014-10-13
      • 1970-01-01
      • 2021-03-22
      • 1970-01-01
      • 2017-08-28
      • 2012-08-10
      相关资源
      最近更新 更多