I am building a magazine website with an issue
custom post type. The slugs for each issue follow the format YYYY-MM-DD
according to the issue's publish date. Currently the permalinks are set up as http://host/magazine/2014-06-08
but I would like them to be accessed through the URL http://host/magazine/2014/06/08
.
Here is what I'm currently doing in my functions.php
:
$issue_structure = '/magazine/%issue%';
$wp_rewrite->add_rewrite_tag("%issue%", '(\d{4}-\d{2}-\d{2})', "issue=");
$wp_rewrite->add_permastruct('issue', $issue_structure, false);
I tried adding this to my .htaccess file:
RewriteRule ^magazine/(\d{4})/(\d{2})/(\d{2}) /magazine/$1-$2-$3 [QSA,L]
And I also tried added this to my WP_Rewrite rules:
add_rewrite_rule('magazine/(\d{4})/(\d{2})/(\d{2})', 'magazine/$matches[1]-$matches[2]-$matches[3]', 'top');
Neither of those approaches have worked, either separately or in combination. And I was careful to flush my rewrite rules. In fact, there's no evidence of that add_rewrite_rule
call in my Rewrite Rules Inspector list, so I suspect I'm not using it correctly.
Another (hacky) thing I tried was manually tweaking the post_name
field in the database to be 2014/06/08
and switching up the rewrite tag to be $wp_rewrite->add_rewrite_tag("%issue%", '(\d{4}/\d{2}/\d{2})', "issue=");
but that didn't work either.
What else should I try?