I'm building a Wordpress site with several custom post types. Every post type is a different magazine. I have also a custom meta fields for a magazine year and issue.
I would like to have urls (used archive.php):
http://my_site/magazine/name/
http://my_site/magazine_name/year/
http://my_site/magazine_name/year/issue/
I made it by code:
function magazine_rewrite_tag() {
add_rewrite_tag('%issue_year%', '([0-9]{4})');
add_rewrite_tag('%issue%', '([0-9])');
}
add_action('init', 'magazine_rewrite_tag', 10, 0);
and:
function magazine_rewrite_rules() {
add_rewrite_rule('^([a-z]+)/([0-9]{4})/([0-9])?', 'index.php?post_type=$matches[1]&issue_year=$matches[2]&issue=$matches[3]', 'top');
add_rewrite_rule('^([a-z]+)/([0-9]{4})?', 'index.php?post_type=$matches[1]&issue_year=$matches[2]', 'top');
}
add_action('init', 'magazine_rewrite_rules');
Off course I have also a custom queries in archive.php. And it works fine.
But now, my urls for single articles doesn't work. By default, it is:
http://my_site/magazine/post-title
but it's show all articles from magazine like url (and it used archive.php template):
http://my_site/magazine/
How add properly rewrite rules for single custom posts? It is possible, I would like to have urls for single post (only for chosen custom post types) in this format:
http://my_site/magazine/year/issue/post-title
10
is the default priority. You can leave both off in that case … or try a higher number. (2) Have you checked the resulting rewrite rules? Also make sure you check the order of those rules as they are processed in their order. Dump$GLOBALS['wp_rewrite']
. (3) Have you addedquery_vars
that might conflict?