add_action( 'pre_get_posts', 'exclude_cpt' );
function exclude_cpt( $query ) {
if ( ($query->is_archive('region') && $query->is_main_query() && ! is_admin()) OR ($query->is_archive('discover') && $query->is_main_query() && ! is_admin()) OR ($query->is_archive('area') && $query->is_main_query() && ! is_admin()) OR ($query->is_archive('destination') && $query->is_main_query() && ! is_admin()) OR ($query->is_archive('counties') && $query->is_main_query() && ! is_admin()) OR ($query->is_archive('towns') && $query->is_main_query() && ! is_admin()) ) {
$query->set( 'post_type', array('sight') );
}
return $query;
}
It works fine, but it doesn't if I activate AJAX pagination. On the first archive load it is ok, but if I click on the "next" link it loads also the not required CPTs.