I’ve got an event
custom post type, and using filters, I’ve configured the archive page to show only event in the future, and in chronological order based on a meta value (start date).
I want to make a second archive page to show events in the past, complete with pagination, ordered reverse chronologically on the same meta value.
My first thought is to use a shortcode inside a normal page, but I’m not sure how to get the pagination working.
Alternatively, is there a way to create a “generic” archive page? Do I need to get into rewrite rules?
I had this same issue of needing two archive pages for a custom post type. I was able to accomplish this fairly cleanly using four WP hooks
For the example my custom post type is “member”. I need a second archive url for members that have a custom meta_key “plus” set to true.
First we need to define the URL for the second archive url. Notice passing the “plus_member” var in the query string.
Next we need to allow the “plus_member” we are passing along
Next we need to tell WP to use a different template file for this request instead of the default “archive-member.php”
Finally we need to alter the main query so we are not showing all members but only plus members.
This should produce the result:
/members/ (loads) archive-member.php (showing) all members
/plus-members/ (loads) archive-plus-member.php (showing) all members where meta_key plus == true
I would use a query parameter, something like
?time=future
maybe, to shift your query. The difference between the future posts query and the past posts query should just be theorderby
and themeta_query
, so it should be relatively easy to change that based on the URL parameter. You also have the added benefit of reducing overhead by keeping it to one page. My only concern with this would be linking in the menu, as you’d have to use custom links, and those are less flexible.This is what I went with. It creates a second archive for past events. It shows upcoming events in the main event archive, and old events in the past events page. Sorting is ascending for the main archive (so you see the next upcoming event first), and descending for the past events page, so you see the most recent event first. It allows for paging on the past events page. Note that is does not modify the query in the admin system.