如何在Wordpress中获得特定分类法的术语?

问题描述

我正在从事房地产项目,需要获得特定分类法的条款。我的意思是其所在州的城市属性。 这是我编写的代码:

RespawnManager

我需要列出州立城市的属性,如何更改这些代码?

解决方法

我自己找到了答案,我想列出具有特定状态的特定状态的属性。 例如状态为(租金)的喀布尔州的属性,以及该州每个城市的属性。

<?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. '&nbsp;('. $count .')';?>
                            </a>
                        </li>
                    </ul>
                <?php
                
                }
                
                ?>

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...