woocommerce offtopic - add_rewrite_rule() returns 404 page

admin2025-06-03  2

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 /?filter_category=crime the result is ok. But I would expect this URL 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?

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748957898a315153.html

最新回复(0)