I would like to get the first page of an archive. I have an archive with events. /events display events, which are not finished yet. /events?past display past events. I use get/remove_query_arg
to generate an URL for a link, so that users can switch between past and future events. The problem is, if user is at page x in past events and try to switch to future events. Future events may not have the page x. This results in an error. URL is generated like this:
esc_url(remove_query_arg('past'))
esc_url(add_query_arg('past', ''))
This method preserves the page number within the URL:
at /events/page/88?past
URL for future events becomes /events/page/88
, which doesn't exist.
I was wondering if there is a "WordPress way" of doing this?
I would like to get the first page of an archive. I have an archive with events. /events display events, which are not finished yet. /events?past display past events. I use get/remove_query_arg
to generate an URL for a link, so that users can switch between past and future events. The problem is, if user is at page x in past events and try to switch to future events. Future events may not have the page x. This results in an error. URL is generated like this:
esc_url(remove_query_arg('past'))
esc_url(add_query_arg('past', ''))
This method preserves the page number within the URL:
at /events/page/88?past
URL for future events becomes /events/page/88
, which doesn't exist.
I was wondering if there is a "WordPress way" of doing this?
You can get link to post type archive using... ‘get_post_type_archive_link’ function:
esc_url(add_query_arg('past', '', get_post_type_archive_link('events')));