That’s easy, pre_get_posts
applies to all queries, not just those on the frontend. So if you don’t want it to run on admin queries, test if you’re in the admin and exit early!
You might also want to verify that you’re in the main query
add_filter( 'pre_get_posts', function( \WP_Query $query) {
if ( is_admin() ) {
return;
}
if ( ! $query->is_main_query() ) {
return;
}
Remember, pre_get_posts
runs on all queries, regardless of where, be it admin, frontend, XMLRPC, REST API, etc. It will only run on the frontend if you tell it to only run on the frontend.