Я исключаю из результатов поиска Wordpress любые сообщения или пользовательские сообщения с настраиваемой таксономией, установленной для определенных условий. Я хочу иметь возможность добавлять больше таксономий и терминов просто (как в массиве), не дублируя функцию, и убедиться, что я делаю это эффективно.
Может ли кто-нибудь предложить более чистую функцию, которая это приспособит?
/* Exclude from WordPress Search using custom taxonomy */
add_action( 'pre_get_posts', function ( $query ) {
if ( is_admin() || ! $query->is_main_query() ) {
return;
}
// Exclude Terms by ID from Search and Archive Listings
if ( is_search() || is_tax( 'marque' ) ) {
$tax_query = array([
'taxonomy' => 'site_search',
'field' => 'term_id',
'terms' => [ exclude_page ],
'operator' => 'NOT IN',
]);
$query->set( 'tax_query', $tax_query );
}
}, 11, 1 );
/* Exclude from WordPress Search using custom taxonomy */
add_action( 'pre_get_posts', function ( $query ) {
if ( is_admin() || ! $query->is_main_query() ) {
return;
}
// Exclude Terms by ID from Search and Archive Listings
if ( is_search() || is_tax( 'marque' ) ) {
$tax_query = array([
'taxonomy' => 'job_status',
'field' => 'term_id',
'terms' => [ closed ],
'operator' => 'NOT IN',
]);
$query->set( 'tax_query', $tax_query );
}
}, 11, 1 );