好的,我有两个自定义的分类法,分别是“类型”和“国家”,有几十个术语。
在我的分类法中,我基本上使用“类型”和“国家”作为我产品的过滤器。php
现在,左边是“类型”和“国家”的两个过滤器,我的产品都显示在rite上。我想要的是NOT 显示国家/地区类别if im on a certain term.
我试过使用has_term 但它没有起作用。
假设这是我页面左侧的分类过滤器:
<div class="countries">
-country
-country
-country
</div>
 我只想展示一下
IF IT IS NOT THE TERM OF JUICE.这就是我的代码目前的样子:
<?php if ( !has_term(\'juice\', \'types\' ) ): ?>
<div class="countries">
<p>Country</p>
<ul>
<?php
//get the current term
$current_term = get_term_by( \'slug\', get_query_var( \'term\' ), get_query_var( \'taxonomy\' ) );
//then set the args for wp_list_categories
 $args = array(
  \'child_of\' => $current_term->term_id,
  \'taxonomy\' => \'countries\',
  \'hide_empty\' => 1,
  \'order\'      => \'ASC\',
  \'show_count\'     => 1,
  \'hierarchical\' => true,
  \'depth\'  => 1,
  \'title_li\' => \'\'
    );
 wp_list_categories( $args );
?>
</ul>
</div><!--countries end-->
<?php endif; ?>
 只需提供正确条件的帮助,以说明如果不在juice的类别(术语)中,则显示国家/地区过滤器,但如果在juice的术语中,则不显示国家/地区术语列表div。(因为juice没有国家/地区)
<?php if ( !has_term(\'juice\', \'types\' ) ): ?>
 
                    最合适的回答,由SO网友:Pieter Goosen 整理而成
                    我相信你在寻找is_tax()而不是has_term(). has_term() 基本上只是检查一篇文章是否属于给定的术语is_tax() 另一方面,检查您是否在分类法归档页面上。
因此,您可以更改此代码
if ( !has_term(\'juice\', \'types\' ) ): 
 至
if ( !is_tax( \'types\', \'juice\' ) ):
 这仅仅意味着如果当前分类法归档页不属于
juice, 做点什么