1

I have a custom URL structure for my WooCommerce setup. Essentially, I have a custom taxonomy (pwb-brand) with the same base as the default (product_cat) taxonomy. To make pagination for both product categories and brands work, I used a piece of code to help WordPress distinguish brands from product categories. This works, but creates a situation where nested categories pages return a 404. To illustrate, site.com/catalog/brand and site.com/catalog/category work fine, pagination included, but site.com/catalog/category/subcategory returns a 404. Here's the code:

// Fix pagination
function wc_categories_might_be_brands( $query ) {
  if( ! is_admin() && isset( $query->query_vars['product_cat'] ) ){
    $term = get_term_by( 'slug', $query->query_vars['product_cat'], 'product_cat' );
    if( false == $term ){
      $query->query_vars['pwb-brand'] = $query->query_vars['product_cat'];
      unset( $query->query_vars['product_cat'] );
    }
  }
}
add_action( 'parse_request', 'wc_categories_might_be_brands' );

How do I modify it to account for subcategories or skip checking subcategory queries altogether (because brands have no nested terms)?
I'm a noob with PHP. Please explain like I'm 5.
Thank you!

  • If I don't use the code above, then subcategories work, but pagination doesn't in either brands, categories or subcategories... – somepaulo Mar 26 at 14:27

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.