最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

woocommerce offtopic - Subcategories not working when using shared base with custom taxonomy

programmeradmin1浏览0评论

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/catalog/brand and site/catalog/category work fine, pagination included, but site/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!

发布评论

评论列表(0)

  1. 暂无评论