$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>paginate links - How to get URL for the first page of post archive|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

paginate links - How to get URL for the first page of post archive

matteradmin9PV0评论

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
Add a comment  | 

1 Answer 1

Reset to default 0

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')));
Post a comment

comment list (0)

  1. No comments so far