• Resolved Gemfruit

    (@gemfruit)


    I’ve recently learned that it’s much better to use pre_get_posts rather than query_posts. I’ve noticed that all usage I’ve found consists of adding a function to functions.php, which requires conditions to not mess up queries around the rest of the website.

    My question is this, is it viable to simply add a function to your template file(s), and use the custom querying there? I have a specific file in mind that I would be editing, where as the rest of the site can remain the same, so it just makes sense to me that I would leave functions.php alone, and add a bit of code to these specific cases. Any thoughts on this are greatly appreciated!

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘pre_get_posts Within Template File’ is closed to new replies.