I have been following the steps on the answer here and it worked wonders.
But my problem is on this part,
on the original:
add_filter('rewrite_rules_array', 'mmp_rewrite_rules');
function mmp_rewrite_rules($rules) {
$newRules = array();
$newRules['custom-post-type-base/(.+)/(.+)/(.+)/(.+)/?$'] = 'index.php?custom_post_type_name=$matches[4]'; // my custom structure will always have the post name as the 5th uri segment
$newRules['custom-post-type-base/(.+)/?$'] = 'index.php?taxonomy_name=$matches[1]';
return array_merge($newRules, $rules);
}
my version:
add_filter('rewrite_rules_array', 'mmp_rewrite_rules');
function mmp_rewrite_rules($rules) {
$newRules = array();
$newRules['custom-post-type-base/(.+)/(.+)/(.+)/?$'] = 'index.php?custom_post_type=$matches[3]';
$newRules['custom-post-type-base/(.+)/?$'] = 'index.php?custom_taxonomy=$matches[1]';
return array_merge($newRules, $rules);
}
Since my taxonomy has two levels, it couldn't recognize whether the 2nd param (custom-post-type-base/(.+)/[here]/
) is a custom post or a custom taxonomy..
it returns correctly on custom taxonomy but returns 404 on a custom post type with the post type being categorized on the parent taxonomy.
See Sample URLS:
"/custom-post-type-base/taxonomy-parent/taxonomy-child/single-custom-post-type/"
/*works as single custom post*/
"/custom-post-type-base/taxonomy-parent/taxonomy-child/"
/*works as custom taxonomy page*/
"/custom-post-type-base/taxonomy-parent/"
/*works as custom taxonomy page too*/
"/custom-post-type-base/taxonomy-parent/single-custom-post-type/"
/*returns a 404*/
#basename/(.+)/[here]/(.+)/?$#