I try to create rewrite rule for my custom post type. I need it to be something like “/%post_type_name%/%taxonomy_slug/%post_slug%”. Here’s the code I used to add rule:
add_action('init', 'episodes_rewrites_init');
function episodes_rewrites_init(){
add_rewrite_rule(
'^episodes/([^/]*)/([^/]*)/?$',
'index.php?post_type=episodes&seasons=$matches[1]&episodes=$matches[2]', 'top'
);
}
It doesn’t work and i can’t figure out why. Please help.
Well mate, I have never used
add_rewrite_rule
, WP codex says that isIt is most commonly used in conjunction with add_rewrite_tag()
.So just I show you how veterans used to do this rewriting rules in the old times.
But moreover If you are building a plugin for the masses you must avoid use
WP 3.5 features
Much people still use WP2.*.These set of actions can help you:
Well, I’ve just installed plugin called “Custom Post Type Permalinks”, added url template for my custom post like “/%seasons%/%postname%/” and now it rewrites urls like I want. But I still don’t know how to do it in code though…