• Resolved Tijmen Smit

    (@tijmensmit)


    The code below is part of a bigger query that by itself works fine.

    But let’s say you have three posts.

    1. post a is assigned to category a
    2. post b is assigned to category b
    3. post c is assigned to category a and b.

    What happens now if you select category a and b is that it returns all three posts. But I want it to only return post c, which the code below doesn’t do.

    INNER JOIN $wpdb->term_relationships AS term_rel ON posts.ID = term_rel.object_id
    INNER JOIN $wpdb->term_taxonomy AS term_tax ON term_rel.term_taxonomy_id = term_tax.term_taxonomy_id
    AND term_tax.taxonomy = 'store_category'
    AND term_tax.term_id IN (" . implode( ',', $filter_ids ) . ")

    Instead of using IN I tried to do this, but that returns no results at all.

    AND term_tax.term_id = category a id
    AND term_tax.term_id = category b id

    Anyone who can point me in the right direction so that it only returns results that have all categories assigned to them?

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Only return posts that are assigned to both categories’ is closed to new replies.