Answer the question
In order to leave comments, you need to log in
Permalinks with rewrite_rule. The head is already broken. How?
Good evening.
I've been scratching my head over this for a long time, to no avail. It's time to finally solve it.
The default permalink settings in wordpress do not allow you to change URLs for custom post types and taxonomies. The plug-in "Types" used also does not have such functionality. A glimmer of hope came with the "Custom Post Type Permalinks" plugin, but it's not enough. I couldn’t understand his code, it’s just hell.
I'll outline the situation.
There is one custom post type and several custom taxonomies.
"http://site.ru/%тип поста%/%slug записи%"
"http://site.ru/%таксономия%/%slug таксономии%"
"Россия" - "Москва и московская область" - "Мытищи"
"http://site.ru/%таксономия%/%slug таксономии%"
displays different records for different session values. "http://site.ru/%таксономия%/%slug таксономии%"
"http://site.ru/%город%/%таксономия%/%slug таксономии%"
"http://site.ru/%таксономия%/%slug таксономии%/%город%"
, not yet determined). "add_rewrite_rule"
, but there was no success. Yes, and sensible manuals have not found. And if I find it, then either I compose the regular expressions incorrectly, or the rule itself does not work. Answer the question
In order to leave comments, you need to log in
Such rewrire rules are not an easy thing, because, as you noticed, there is practically no documentation and lessons on this topic. About two years ago I did a similar thing with cities for one WP-based SaaS platform. As a result, he did, but he killed more than one night for this, the mosk almost broke. Now I don’t remember the details from the start, but the plus or minus logic is as follows:
1. add_rewrite_tag - create template tags %city% and so on
2. register new variables for query through the query_vars filter
3. create rewrite_rules
The most important thing is regular expressions that will be your rewrite tags (1) parse into query variables (2). That is, the resulting string will eventually be like index.php?post_type=XXX&taxonomy1=YYY&taxonomy1_term=ZZZ&taxonomy2=WWW&taxonomy2_term=UUU
And in general, for starters, do step 2 and make sure that everything works for you with "ugly urls", and only then - take care of CNC. Because with rewrite rules, most often the trouble is that the query vars are wrong.
Well, then the URLs of the links themselves (permalinks) will need to be built in the required format. There are some hooks, but it's not difficult anymore.
In general, get ready for a lot of debugging, stock up on coffee Query Monitor and Rewrite Rules Inspector to help.
If you persistently explore the results of Google after the 3rd page, try different key phrases, then you should find 2-3 lessons, more or less deep. There were definitely 2 pieces on some site, it seems with the word Shiba in the title. I'll rummage through the archives at my leisure, maybe I'll find it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question