admin管理员组文章数量:1130349
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?
Share Improve this question asked Dec 24, 2018 at 17:22 Saren TasciyanSaren Tasciyan 1134 bronze badges 2- Is that a custom post type archive? What is the slug for that CPT? – Krzysiek Dróżdż Commented Dec 24, 2018 at 17:31
- @KrzysiekDróżdż yes it is and the slug is "events". – Saren Tasciyan Commented Dec 24, 2018 at 17:39
1 Answer
Reset to default 0You 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')));
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?
Share Improve this question asked Dec 24, 2018 at 17:22 Saren TasciyanSaren Tasciyan 1134 bronze badges 2- Is that a custom post type archive? What is the slug for that CPT? – Krzysiek Dróżdż Commented Dec 24, 2018 at 17:31
- @KrzysiekDróżdż yes it is and the slug is "events". – Saren Tasciyan Commented Dec 24, 2018 at 17:39
1 Answer
Reset to default 0You 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')));
本文标签: paginate linksHow to get URL for the first page of post archive
版权声明:本文标题:paginate links - How to get URL for the first page of post archive 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749070254a2311462.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论