Few remarks:
- I use
pre_get_posts
as an action hook, not as a filter. - You should use
! is_admin()
to prevent this from changing your backend views. - You should skip the
'relation' => 'OR',
since you only have a singletax_query
filter - Is there any reason why you have to modify the post type ? Is your custom taxonomy attached to multiple post types?
so you could try this modification instead:
add_action( 'pre_get_posts', 'change_archive_loop' );
function change_archive_loop( $query ) {
$choduyet = intval( get_option( 'zen-id_cho_duyet' ) );
$baocao = intval( get_option( 'zen-id_bao_cao' ) );
if ( ! is_admin() && $query->is_tax( 'tinh-trang' ) && $query->is_main_query() ) {
$terms = array( $choduyet, $baocao );
$query->set( 'tax_query', array(
array(
'taxonomy' => 'tinh-trang',
'field' => 'id',
'operator' => 'NOT IN',
'terms' => $terms
)
) );
}
}