I’ve added custom shared taxonomy season for product type from woocommerce and my custom type care. Care type and taxonomy are created in functions.php file of my custom theme.

add_action('init', function() {
    register_post_type('care', array(
        'labels' => array(
            'name' => __('Cares'),
            'singular_name' => __('Care'),
        ),
        'menu_position' => 4,
        'public' => true,
        'show_ui' => true,
        'has_archive' => true,
        'publicly_queryable' => true,
        'supports' => array('title')
    ));

    register_taxonomy( 'season',
        array('product', 'care'),
        array(
            'label' => __('Season'),
            'show_ui' => true,
            'hierarchical' => true,
        )
    );
});

Now when I access season taxonomy term, no matter which post_type been passed, I always get to woocommerce products archive, i.e. http://example.com/?season=helloworld&post_type=product and http://example.com/?season=helloworld&post_type=care lead to the same page with woocommerce products archive.

How to make woocommerce share taxonomy properly?

P.S. Using WordPress 3.8.1 and Woocommerce 2.0.20. No explicit rewrite rules added.

1 Answer
1

Found solution for this problem.

It turned out that woocommerce affects post_type query variable in pre_get_posts filter without checking that another post_type has been requested. It’s done in WC_Query.product_query method:

if ( ! $q->is_tax( 'product_cat' ) && ! $q->is_tax( 'product_tag' ) )
    $q->set( 'post_type', 'product' );

Fix for this problem is simple. You just need to check that product post type has been actually requested in the beginning of product_query method:

// Check that product post type has been requested
if ($q->get('post_type') != 'product')
    return;

After that everything works fine.

Update:
Fix has been merged into woocommerce master branch: https://github.com/woothemes/woocommerce/pull/4582.

Leave a Reply

Your email address will not be published. Required fields are marked *