You’re creating a new query, not altering the existing one.
The pre_get_posts codex page has a note explaining that the $query argument is passed by reference and you should alter it directly. There’s no need to declare globals or return values. Update your function to be:
add_action( 'pre_get_posts', 'only_current' );
function only_current( $query ) {
if ( is_admin() ) {
return;
}
if ( ! $query->is_main_query() ) {
return;
}
if ( ! is_post_type_archive( 'research' ) ) {
return;
}
$tax_query = array(
array(
'taxonomy' => 'status',
'field' => 'slug',
'terms' => 'current',
),
);
$query->set( 'tax_query', $tax_query );
}
The pre_get_posts
filter also applies to queries within the admin, so I’ve added another if statement to check we’re on the front end of the site.
I’ve also added a statement to check we’re on the research
archive page.
The function above needs to be put in your functions.php
file, or a site specific plugin. Placing it in the archive-research.php
file will not work because the query will have been run by the time the archive-research.php
template is loaded.