• Resolved hrohas

    (@hrohas)


    Hello!

    Do you know how I can filter products with several categories at the same time using woocommerce rest api v3?

Viewing 7 replies - 1 through 7 (of 7 total)
  • Hi @hrohas

    Thanks for reaching out!

    To fetch all products in a certain category, you can use the products API with the category parameter:

    /wp-json/wc/v3/products?category=ID

    Replace ID with the ID of your category. You can find more information here:
    https://woocommerce.github.io/woocommerce-rest-api-docs/#list-all-products

    If you need one or more categories, you can add a comma every after ID such as:

    wp-json/wc/v3/products/?category=ID1,ID2

    Hope this helps!

    Thread Starter hrohas

    (@hrohas)

    I tried this, but its return products with ID1 first and ID2 too. But I need products, which contains both IDs only. How I can do this?

    Hello,

    Do you mean products related to multiple categories? I’ve found a report on GitHub about it, please check:
    https://github.com/woocommerce/woocommerce/issues/24179

    If you meant something different, please provide us with more information.

    • This reply was modified 3 years, 7 months ago by Igor H.

    I could use some help on this as well. As in the link provided, is there a way to use AND logic instead of OR logic on the request.

    Hi there @ngonzales07 👋

    I could use some help on this as well. As in the link provided, is there a way to use AND logic instead of OR logic on the request.

    I suggest you leave a comment on the GitHub issue about this. Kindly note that it is marked as closed, though.

    Just to clarify, how viable of an alternative, for your particular use case, is to create a new category, which includes products of 2 or more categories, and query for that new category instead?

    I am wanting to figure out how I can get an “AND” join on the ‘product_cat’ categories. As the result are coming in as an “OR” join.

    api .get(products, { category: 'category_a,category_b', per_page: 16, })

    So this returns all products in “category_a” as well as all products in “category_b”. Is there a way to get all products that have both “category_a” and “category_b” ONLY? I do not want the ones that don’t have both.

    And no have a separate category is not an option as there are hundreds of categories on thousands of products. So making this relation an ‘AND’ instead of an “OR” is a must.

    Saif

    (@babylon1999)

    Hello @ngonzales07,

    We need to address each problem individually in the forums. I know it’s a hassle but can you please open your own thread about this?

    Thanks!

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Fetch products and filter with several categories at the same time’ is closed to new replies.