admin管理员组文章数量:1406221
I’m trying to conditionally display a div if a post object post has a specific custom taxonomy term. The custom taxonomy is called ‘room_vacancy’ and the term is called ‘booked’
I’m using the following code but it doesn’t work:
<?php $post_objects = get_field('bedrooms_object');
if( $post_objects ): ?>
<h2>Bedrooms</h2>
<ul class="bedrooms">
<?php foreach( $post_objects as $post_object): ?>
<li class="bedroom">
<div class="inner row">
<div class="col-md-5 image">
<?php if ( is_tax( 'room_vacancy', 'booked') ) { ?>
<div class="label">Booked</div>
<?php } else { ?>
<?php } ?>
<img class="lazy" src="<?php echo get_the_post_thumbnail_url($post_object->ID, 'large'); ?>"/>
<div class="details">
<div class="price">Price <span><?php the_field('room_price', $post_object->ID); ?><span></div>
<div class="size">Size: <span><?php the_field('room_size', $post_object->ID); ?></span></div>
</div>
</div>
<div class="col-md-7 content">
<h2><?php echo get_the_title($post_object->ID); ?></h2>
<?php the_field('listing_content', $post_object->ID); ?>
<a class="btn" href="<?php the_field('button_url', $post_object->ID); ?>">Apply Now</a>
</div>
</div>
</li>
<?php endforeach; ?>
</ul>
<?php endif;?>
Any advice on how to do this?
I’m trying to conditionally display a div if a post object post has a specific custom taxonomy term. The custom taxonomy is called ‘room_vacancy’ and the term is called ‘booked’
I’m using the following code but it doesn’t work:
<?php $post_objects = get_field('bedrooms_object');
if( $post_objects ): ?>
<h2>Bedrooms</h2>
<ul class="bedrooms">
<?php foreach( $post_objects as $post_object): ?>
<li class="bedroom">
<div class="inner row">
<div class="col-md-5 image">
<?php if ( is_tax( 'room_vacancy', 'booked') ) { ?>
<div class="label">Booked</div>
<?php } else { ?>
<?php } ?>
<img class="lazy" src="<?php echo get_the_post_thumbnail_url($post_object->ID, 'large'); ?>"/>
<div class="details">
<div class="price">Price <span><?php the_field('room_price', $post_object->ID); ?><span></div>
<div class="size">Size: <span><?php the_field('room_size', $post_object->ID); ?></span></div>
</div>
</div>
<div class="col-md-7 content">
<h2><?php echo get_the_title($post_object->ID); ?></h2>
<?php the_field('listing_content', $post_object->ID); ?>
<a class="btn" href="<?php the_field('button_url', $post_object->ID); ?>">Apply Now</a>
</div>
</div>
</li>
<?php endforeach; ?>
</ul>
<?php endif;?>
Any advice on how to do this?
Share Improve this question asked Nov 20, 2019 at 15:14 Ciaran GaffeyCiaran Gaffey 911 gold badge3 silver badges16 bronze badges1 Answer
Reset to default 0Instead of is_tax()
, which
Determines whether the query is for an existing custom taxonomy archive page.
you should use has_term()
,
Check if the current post has any of given terms.
Like so,
if ( has_term( 'booked', 'room_vacancy', $post_object ) ) {
// Yay!
}
本文标签: If ACF Post Object post has custom taxonomy term…
版权声明:本文标题:If ACF Post Object post has custom taxonomy term… 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744987615a2636185.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论