0

I have created this new rewrite rule but it matches some patterns but does not match others when both are identical. For example:

for category/resources/newsletters/2017 it loads category-newsletters.php but for category/resources/newsletters/2014 i see 404 page.

(I generate permalink structure everytime i change rewrite rule)

remove_filter('template_redirect', 'redirect_canonical');

function cd_rewrite_rule() {
    add_rewrite_rule('^category/resources/newsletters/([0-9]+)/?','index.php?category_name=newsletters&year=$matches[1]','top');

    add_rewrite_tag('%year%', '([0-9]+)');
}
add_action('init', 'my123_rewrite_rule');

Using debug plugin I have found that different query strings are being applied for same pattern requests.

category/resources/newsletters/2017 => year=2017&category_name=newsletters

category/resources/newsletters/2014 => category_name=newsletters&name=2014

  • 1
    It sounds like you have conflicting terms - for example you have a taxonomy called name that contains year values, but also year that contains year values. The safest way to proceed is to consolidate so you don't have any terms with duplicate slugs. Otherwise WP will continue to get confused about which one you're requesting. – WebElaine Sep 25 '17 at 19:35
  • Sorry forgot to update here. I changed parameter year to something else and it started working. You can answer this question and i will mark is as accepted. – mysterious Sep 26 '17 at 8:00
1

It sounds like you have conflicting terms - for example you have a taxonomy called name that contains year values, but also year that contains year values. The safest way to proceed is to consolidate so you don't have any terms with duplicate slugs. Otherwise WP will continue to get confused about which one you're requesting.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.