0

Using this code here:

    add_filter( 'rewrite_rules_array', function( $rules )
{
    $new_rules = array(
        'services/([^/]*?)/page/([0-9]{1,})/?$' => 'index.php?product_cat=$matches[1]&paged=$matches[2]',
        'services/([^/]*?)/?$' => 'index.php?product_cat=$matches[1]',
    );
    return $new_rules + $rules;
} );

and having these permalink settings

product category base: services

product permalink - custom base: /services/%product_cat%

I get the following:

/services/%category_name%/ (Parent Product Category Page works fine)

/services/%category_name%/%subcategory_name/ (Child Product Category Page does not work - gets 404)

/services/%category_name%/%subcategory_name/%product_name (Single Products - works fine)

Anybody have any insight on how to get the Child Product Category pages to not throw the 404 error?

Thanks!

1 Answer 1

0

Try this

add_filter( 'rewrite_rules_array', function( $rules )
{
    $new_rules = array(
        'services/([^/]*?)/page/([0-9]{1,})/?$' => 'index.php?product_cat=$matches[1]&paged=$matches[2]',
        'services/([^/]*?)/?$' => 'index.php?product_cat=$matches[1]',
        'services/([^/]*?)/([^/]*?)/?$' => 'index.php?product_cat=$matches[2]'
    );
    return $new_rules + $rules;
} );
1
  • 2
    Please, explain what the code does and how it answers the quesiton. Just dumpling code is not a good answer.
    – cybmeta
    Jul 11, 2017 at 8:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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