我想要一个字段显示它是否具有来自2个不同子字段的2个值的类别。筛选2个不同的类别值
我不太清楚如何做到这一点,虽然有2个不同的子领域。
这里是一个〔实施例即时试图演示,以证明我想它是如何工作的:
<?php while(has_sub_field('team_profile')):
$category = get_sub_field('category');
$category_2 = get_sub_field('category_2');
if($category=='copyclearance')
if($category_2=='anothercat'){ ?>
<li class="col-lg-2 teamProfile">
<img src="<?php the_sub_field('profile_image'); ?>" class="img-responsive"/>
<h2><?php the_sub_field('profile_name'); ?></h2>
<p class="jobTitle"><?php the_sub_field('job_title'); ?></p>
</li>
<?php
}
endwhile; ?>
这是我的工作版本只有一个类别过滤器(但我需要2个):
<?php while(has_sub_field('team_profile')):
$category = get_sub_field('category');
if ($category=='copyclearance') { ?>
<li class="col-lg-2 teamProfile">
<img src="<?php the_sub_field('profile_image'); ?>" class="img-responsive"/>
<h2><?php the_sub_field('profile_name'); ?></h2>
<p class="jobTitle"><?php the_sub_field('job_title'); ?></p>
</li>
<?php
}
endwhile; ?>
所以这将工作,通过查看是否有任何东西已张贴在$category
或$category_2
然后显示所有结果。不使用2过滤明确,即只显示帖子说是在这两个$category
和$category_2
旁注:确保您总是在您的if语句中使用'{}'。在你的第一个例子中,如果你不这样做,你可能会遇到一些麻烦,而且它总是最佳实践,因为它使代码更加清晰,并且避免了难以追查的错误。苹果最近因此发生了巨大的失败 - 尽早开始并保持警惕。 – Jeff