Totally agree with you. I’ve tried to filter by collection_id and metafield separately. It’s working correctly. But when I combine both, it doesn’t work anymore
I can confirm that you are filtering this query correctly, and this should work.
This is actually a known issue that our developers are currently aware of, specifically with the collection_id fitler not working when combined with certain other filters such as the metafield filter.
I’ve reached out to our developers internally to help look into this further and we will keep you updated here as soon as we have any more information to share. Though in the meantime, I know it’s not ideal, but I may recommend filtering the products query with the metafield fitler, and using the inCollection field on the product object to see if the returned products are in the collection you’re trying to filter for or not.
I also encountered a similar bug with product queries.
Inaccurate results occur when complex conditions are combined.
In the end, I worked around the issue by using multiple queries.
From the screenshots, the combined query looks like it’s targeting a different metafield than the one you proved exists. In screenshot 1 you read sapo.optimizationSite, but in screenshot 2 you filter on $app.optimizeState. Since products(query: ...) does support combining collection_id with metafield filters, I would first double-check the exact namespace/key and whether that metafield definition is filterable.
I do understand it’s not ideal, especially if you’re needing to paginate over a large amount of results, though it’s not impossible with the workaround, you’d just need to paginate through all of the results filtered by metafield, then cache the results on your end and parse through them, removing any results that have inCollection: false.
Alternatively, you can use Bulk Operation Queries to request ALL results at once, and not have to paginate through the results, though this is an asynchronous operation, and you’ll still need to parse the results after, removing any results that have inCollection: false