[英]How get terms of specific taxonomy in wordpress?
我正在从事房地产项目,需要获得特定分类法的条款。 我的意思是城市基础的属性。 这是我编写的代码:
<div class="row">
<div class="col-md-2">
<?php
$taxonomy = 'property-state';
$terms = get_terms($taxonomy);
?>
<ul>
<?php foreach ( $terms as $term ) { ?>
<li>
<a href="<?php echo get_term_link($term->slug, $taxonomy); ?>">
<?php echo $term->name . ' ('. $term->count .')' ?>
</a>
</li>
<?php } ?>
</ul>
<?php
?>
</div>
<div class="col-md-2">
<?php
$taxonomy = 'property-city';
$terms = get_terms($taxonomy);
?>
<ul>
<?php foreach ( $terms as $term ) { ?>
<li>
<a href="<?php echo get_term_link($term->slug, $taxonomy); ?>">
<?php echo $term->name . ' ('. $term->count .')'?>
</a>
</li>
<?php } ?>
</ul>
<?php
?>
</div>
</div> <!-- end of row -->
我需要的是列出州基础城市的属性,我应该如何更改这些代码?
我自己找到了答案,我想列出具有特定状态的特定状态的属性。 例如,状态为(出租)的喀布尔州的财产以及该州的每个城市的财产。
<?php $terms = get_terms("property-city");
foreach($terms as $term)
{
$items = get_posts(array(
'numberposts' => -1,
'post_type' => 'property',
'post_status' => 'publish',
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'property-city',
'field' => 'slug',
'terms' => $term->slug
),
array(
'taxonomy' => 'property-state',
'field' => 'name',
'terms' => 'هرات',
'operator' => 'NOT IN'
),
)
));
$count = count( $items );
?>
<ul>
<li>
<a href="<?php echo get_term_link($term);?>" <?php if ($count == 0) echo " style='display: none';"; ?>>
<?php echo $term->name. ' ('. $count .')';?>
</a>
</li>
</ul>
<?php
}
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.