Query reset problem or flawed code to enable custom post type query

pre_get_posts runs on every query, so you want to check if is_main_query() so it only applies to the default query and not additional queries you run on the page.

You should also get in the habit of referencing the query object passed to the function like $query->is_category(), as calling is_category() is a wrapper for $wp_query->is_category(), which may also have unexpected results depending on what you’re trying to do.