Let's say I have a post type "highschool" and I have a url structure for them like:
/highschool/hs1
/highschool/hs2
, etc.
I want to add some functionality like course booking but due to SEO/cache and other reason I don't what to use URL params like ?applyto=true but use URL structure like:
/highschool/hs1/applyto
/highschool/hs2/applyto
I try to use url rewrite like this:
add_action( 'init', 'add_booking_rules' );
function add_booking_rules() {
add_rewrite_rule(
'highschool/([^/]+)/applyto/?$',
'index.php?highschool=$matches[1]&applyto=true',
'top');
}
but then I go ti URL /highschool/hs1/applyto it is just redirected me to /highschool/hs1/
so, as you use rewrite rules to handle custom posts it will be great if you could advise me what is wrong with my approach.

Nigel
Supporter
Languages:
English (English )
Spanish (Español )
Timezone:
Europe/London (GMT+01:00)
Hi there
I'm sorry, but in support we don't have any special insight into custom rewrite rules.
We can point you towards where to add simple rewrite rules in the settings for the post type, or direct you towards WordPress documentation about implementing rewrites, but we can't come up with custom rewrite rules for you.
The main reference for rewrite rules is at: https://developer.wordpress.org/apis/handbook/rewrite/
I've found this guide helpful myself, although there are many more guides available when searching:
hidden link

Minesh
Supporter
Languages:
English (English )
Timezone:
Asia/Kolkata (GMT+05:30)
In addition to that, if you would like, you can add the plugin that offers such pretty permalink structure:
- https://wordpress.org/plugins/permalink-manager/
- https://wordpress.org/plugins/custom-permalinks/
- https://wordpress.org/plugins/custom-post-type-permalinks/
You can use any of the plugin that suits best as per your requirement.
Thanks a lot for your help.
The question is not about rewrite rules in general - I find and use some references also.
The question is about how you process it in Toolset.
To be clear - if I will make this rules for the page, like
/pageforapplication/hs1/
/pageforapplication/hs2/
there hs1 and hs2 just a slug for Highschool custom posts
then they processed correctly with rewrite rule and I have no issues.
But if I want to add redirect rule as an extension after custom post like
/highschool/hs1/applyto
/highschool/hs2/applyto
then it just redirect me to the post itself to URLs:
/highschool/hs1/
/highschool/hs2/
Thats why I suppose this is not the problem of url rewrite, but the problem of how it combined with Toolset rewrites or rewriten URL processed within Toolset

Minesh
Supporter
Languages:
English (English )
Timezone:
Asia/Kolkata (GMT+05:30)
Toolset do not offer such custom rewrite mechanism.
If you disable the Toolset and then try to register the post type using WordPress core function register_post_type() to create custom post type and then you add the rewrite code you shared you will have the same result. Its not on Toolset.
It will require custom code or you should be know how to deal with such custom rewrite rules. If you require custom programming for your project, please feel free to contact our certified partners:
- https://toolset.com/contractors/