I have read this post: Include and Exclude Taxonomies From Archives & Feeds Using 'pre_get_posts'
And then I have used that function to my theme. My Taxonomy (tinh-trang) had 3 term: 19,20,21 And I want to exclude all post have terms id: 19, 21 when visitor go to any archives.
But I have nothing changed?
add_filter('pre_get_posts','change_archive_loop');
function change_archive_loop( $query ) {
$choduyet = intval(get_option('zen-id_cho_duyet')); // Get term ID 1 from theme option
$baocao = intval(get_option('zen-id_bao_cao')); // Get term ID 2 from theme option
if ( $query->is_tax( 'tinh-trang' ) && $query->is_main_query() ) {
$terms = array($choduyet, $baocao);
$query->set( 'post_type', array( 'post' ) );
$query->set( 'tax_query', array(
'relation' => 'OR',
array(
'taxonomy' => 'tinh-trang',
'field' => 'id',
'operator' => 'NOT IN',
'terms' => $terms
)
) );
}
return $query;
}