Pieter Goosen solved the issue with with this suggestion.
if ( $query->is_home() || $query->is_archive() )
Should be:
if (!is_admin() && $query->is_main_query() && ( $query->is_home() || $query->is_archive() ) )
Then explains why this solution worked:
is_main_query()
only returns true in the main query.pre_get_posts
alters all queries back end and front end, there is no designation
between queries. Because you only want to target the main query with
pre_get_posts
, and not all the other queries, you need exclude all
other queries by checking if the current query is the main query.