如何排除投资组合类别


How to exclude a portfolio category

我有一个主题与投资组合页面,它允许我排除某些投资组合类别,通过取消检查我想隐藏的类别。(如电影、艺术)

问题是某些投资组合项目被分配到多个类别,如果一个类别未被选中,我的主题不会显示投资组合项目,但仍然被分配到一个已选中的类别(因此多个类别)。

我该如何解决这个问题?我想我在我的函数文件中找到了代码,但我不确定。

我尝试将操作符从"NOT IN"更改为"IN",但这最终显示了所有类别。任何帮助将非常感激!

    if ( isset( $cat ) && $cat!=-1 ) {
        //include a category
        $query_args['tax_query'] = array(
            array(
                'taxonomy' => PEXETO_PORTFOLIO_TAXONOMY,
                'field' => 'slug',
                'terms' => $cat
            )
        );
    }
    if ( !empty( $excludeCats ) ) {
        if ( !isset( $query_args['tax_query'] ) ) {
            $query_args['tax_query'] = array();
        }
        //exclude categories
        $query_args['tax_query'][]= array(
            'taxonomy' => PEXETO_PORTFOLIO_TAXONOMY,
            'field' => 'id',
            'terms' => $excludeCats,
            'operator' => 'NOT IN'
        );
    }

我假设这个问题发生在投资组合存档上。如果是这种情况,作为一种解决方法,我建议获取所有可见的类别并将它们添加到tax_query中。

if( ! empty( $excludeCats ) ) {
    $visibleCats = array_diff( $allCats, $excludeCats );
}
if ( !empty( $excludeCats ) ) {
    if ( !isset( $query_args['tax_query'] ) ) {
        $query_args['tax_query'] = array();
    }
    //exclude categories
    $query_args['tax_query'][]= array(
        'taxonomy' => PEXETO_PORTFOLIO_TAXONOMY,
        'field' => 'id',
        'terms' => $visibleCats,
        'operator' => 'IN'
    );
}