我在wordpress中有下面的自定义分类法过滤器代码。但它不起作用。
function alter_query_so_15250127($query) {
$tax_query = array(
'taxonomy' => 'demographic',
'field' => 'id',
'terms' => array( 522 ),
'operator' => 'IN'
);
$query->set( 'tax_query', $tax_query );
}
add_action('pre_get_posts','alter_query_so_15250127');
根据WP_Query
文档,tax_query
是数组的数组:
重要提示:tax_query采用税务查询参数数组的数组(它需要一个数组)。。。。
所以,请试试这个:
function alter_query_so_15250127($query) {
//Add wrapper here
$tax_query = array( array(
'taxonomy' => 'demographic',
'field' => 'id',
'terms' => array( 522 ),
'operator' => 'IN'
) );
$query->set( 'tax_query', $tax_query );
}
add_action('pre_get_posts','alter_query_so_15250127');
我希望这会有所帮助。