I have tried this one for example:

$query = new WP_Query( array( 'tag__and' => array( 37, 47 ) ) );

It doesn't seem to work. Am I wrong in thinking that category and tags are the same relative to the database eg. in the wp_terms table. Both Categories and Tags show up in there.

So I'm looking in wp_term_relationships and I see an object_id for the product that I want, it has the following example term_taxonomy_id's: 48, 45, 43, 38, 37, 33, 24, 23, 15, 8

So in my filter I want to return the product(s) that have all of those tags.

The query above seems to be like a partial(returns products that have some of those tags), I noticed there is also tag__in.

What am I doing wrong?

I don't really get the taxonomy type search, do I have to explicitly state a taxonomy like in the dashboard? I was trying to do this with just "straight SQL" too, I tried the IN operator with a comma separated tag int list in parenthesis and a DISTINCT select... it's ugly, I mean it works but I'm using a combination of SQL and PHP to do the sorting. There's also no pagination/offset so yeah I'm trying to improve this.

This is an off-hand question but I'm also wondering if this is built into WooCommerce by default. That is what this question pertains to but it is specifically about sorting. But I was wondering, I saw there is woocommerce_pagination or is it woo_pagination, but not sure if it just "works out of the box" eg. filter search, pagination with limits/sorting.

Thanks for any help, I'll keep searching/trying stuff.

  • "Am I wrong in thinking that category and tags are the same relative to the database" Yes, you're wrong. If you want to query posts that have a category and a tag then you need to use tax_query. tag__and will not query categories. Sep 20, 2018 at 4:33
  • Okay good point, I'll try that then. Sep 20, 2018 at 4:35

1 Answer 1


To display posts from either tag you need to use tag__in instead of tag__and . This will return posts from either tag id.

$tag_query = new WP_Query( array( 'tag__in' => '13, 27' ) );

Your Answer

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

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