I have a question about reasons why the main query would call the current page's info when using a template file, instead of querying the posts.
If I modify the loop by creating a custom query using
new WP_query, I can access the all the posts on my custom template as I want. However, when I try use the main loop/query on my custom template, with plain-old
the_post() my page seems to querying info about the current page (e.g. when the_title and the_date match that of the current page, not my posts).
What is weird that this doesn't seem to be the case for my front-page. The main query for the front page is fine. Any ideas about why the main functions for the loop like "have posts" would call current the page for the template's info instead of querying the posts? What have I done wrong?
wp_reset_query() after the all loops when i use the main loop, and
wp_reset_postdata() after all loops where I used
@Milo's answer, I have figured out that I misunderstood how WordPress works. I wanted to have custom templates for the achive page for a certain category, e.g. the category "special".
I was using:
- a custom template for the category, with an arbitrary name (e.g.
- and a category-archive reroute in archives.php, which pointed the category to my file , e.g.
I was trying to use the main post query with those custom pages/templates, with arbitrary names.
I now realize that I can accomplish custom category pages that use a post-based main query more elegantly without the rerouting/archive.php solution. The better way is to rename the custom category .php file that I created, that had an arbitrary name ( e.g.
special.php) with a name that matches WordPress' native category convention. This convention requires you to use a
category- prefix in conjunction with the target category-name (e.g
I renamed that custom .php file with the a name using this
category- convention, and deleted the rerouting I had created in archives.php. After taking those two steps, I was able grab posts of those categories only using the main loop functions (e.g.
the_post) AND have custom design/elements/html/php for that category.
There are a lot of intricacies to discover in WordPress but its nice to figure them out!