我正在使用pre_get_posts
使用筛选$wp_query->set( \'tax_query\', $tax_query );
I\'m probably better-off doing this with a new WP_Query
, but if someone knows something I don\'t I\'d love to hear it
问题,我需要设置默认分类法;保留显示所有帖子的功能。例如:
/cpt/?taxo=this
显示所有具有taxo术语==此的cpt。
$taxo_terms = [];
if( !empty( $_GET[\'taxo\'] ) ){
$types = explode(\',\', $_GET[\'taxo\']);
foreach ($types as $key => $val) {
$taxo_terms[$key] = sanitize_key($val);
}
}
else{
$taxo_terms[]=\'this\'; // here\'s where things get ugly.
}
$tax_query = [];
if( !empty($taxo_terms) ){
$tax_query[] = [
\'taxonomy\' => \'taxo\',
\'field\' => \'slug\',
\'terms\' => $taxo_terms,
\'operator\' => \'AND\',
];
$wp_query->set( \'tax_query\', $tax_query );
}
我想添加
/cpt/?taxo=all
显示所有帖子,无论是什么
taxo->terms
他们有。
希望找到一种方法unset
当前tax_query
从循环中,使用pre_get_posts
.
有没有办法$wp_query->UNSET
?
我试过了$wp_query->set( \'tax_query\', null );