2

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.

2
  • 1
    Obvious question. do you have any posts under "care" with the same season? Jan 27, 2014 at 11:00
  • Yes I have. But that doesn't matter.
    – rpeshkov
    Jan 27, 2014 at 11:11

1 Answer 1

2

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.

2
  • if it works and you can do that, please mark it as done/answered/whatever it is called Jan 27, 2014 at 15:25
  • I will accept it 2 days later, because "You can accept your own answer in 2 days".
    – rpeshkov
    Jan 27, 2014 at 15: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.