Whenever you’re working with archive templates in WordPress, posts are typically listed by date in descending order. That is, the most recent posts are listed at the top, and then it goes from there.
Lately, I’ve been working on a few projects that integrate with third-party APIs. These APIs return dates – sometimes two dates, a start date, and an end date – for a given event and customers want to use that information to list posts rather than the date of the post. That is, they want custom archive templates.
It’s not too hard to do this, but before doing so, I think it’s important to give some background information on how the project is built so there’s a bit more context around why, say, a custom query is needed and why you may or may not need to look into pre_get_posts.
I’ll start with a TL;DR first, though. That way, you can get the idea before reading the whole thing.