Why can't you modify the query in a template page?
According to WordPress best practices, the query should only be modified in functions.php.
functions.php
You can modify the query in a template page if you use pre_get_posts().
pre_get_posts()
The query can only be run inside the Loop.
Due to execution order, the query has already run by the time a template is loaded.