[英]Wordpress Advanced Custom Fields if statment
I can't seem to display only the content I request. 我似乎无法仅显示我请求的内容。 I am using the Advanced Custom Fields (ACF) plugin with my Wordpress site, and using a repeater field with a multiple select field for "departments \\ job titles". 我在我的Wordpress网站上使用了高级自定义字段 (ACF)插件,并为“部门\\职务”使用了带有多个选择字段的转发器字段。
With the code below, I am looking to display only the content which has the value that equals what I select. 使用下面的代码,我希望仅显示具有等于我选择的值的内容。 Maybe I am looking at this wrong but the content displays whether the strpos is true or not. 也许我看错了,但是内容显示了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; ?>
Your if statement should be done like this: 您的if语句应像这样完成:
<?php if(get_sub_field('who_is_this_for') == 'strpos') { ?><?php }?>
Where "strpos" is the value you select (if I follow correctly). 其中“ strpos”是您选择的值(如果我正确遵循的话)。
It would probably be beneficial to actually see your fields. 实际查看您的字段可能会有所帮助。
I was on the right track. 我走在正确的轨道上。 It turns out the ACF is converted to an array when multiple values are selected. 事实证明,当选择多个值时,ACF将转换为数组。 I performed an implode to the variable then used the converted string performed the validation. 我对变量执行了爆破,然后使用转换后的字符串进行了验证。 thanks for the help 谢谢您的帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.