0

I'm using add_rewrite_rule function to add this rule:

function custom_rewrite_rules() {

    add_rewrite_rule(
        'category/books/crime',
        'category/books/?filter_category=crime',
        'top'
    );

    flush_rewrite_rules();
}

add_action('init', 'custom_rewrite_rules');

But it only returns Error 404 Page not found.

When I use this kind of URL https://example.com/category/books/?filter_category=crime the result is ok. But I would expect this URL https://example.com/category/books/crime return the same result because of added rewrite rule.

I'm also using WooCommerce plugin where "books" category and "category" attribute with "crime" term are created.

Is there something wrong in my function? If the function is good, where else could be the problem?

  • Did you tried to re-save the permalink settings manually?! – Farsad Jan 31 at 14:01
  • You mean in Settings -> Permalinks -> Save Changes? Yes, I did. – sunergos Jan 31 at 14:08

Your Answer

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

Browse other questions tagged or ask your own question.