Goal: Add products to a collection via Shopify Flow when a product has a specific tag, product type (Shirt or T‑Shirt), and a product metafield Gender equals a value (e.g., Mens).
Key issue: The initial search query failed when using {{shop.gender.value}} for Gender. Product metafields cannot be read from the shop object in a search query.
Working approach:
Use a scheduled Flow trigger, then “Get product data” with a query for tag and product_type (e.g., tag:tag-testing AND (product_type:Shirt OR product_type:T-Shirt)).
Add a “For each” loop over returned products (Flow returns up to 100 per run).
Inside the loop, add a Condition that checks Product > metafields (namespace/key) equals the desired gender value.
If true, “Add product to a collection.”
Notes: Parentheses help ensure correct AND/OR logic. Screenshots provided show the Flow setup but are not required to grasp the solution. Batch size is limited to 100 products per execution.
Outcome: After switching to the product metafield (not shop variable) and correcting the metafield reference in the condition, the Flow worked as intended. Issue resolved.
Summarized with AI on December 18.
AI used: gpt-5.
I’m new to the Shopify Flow app and I’m struggling to build a flow to do the following:
If a product has a specific tag, and has a metafield for a specific gender, and has a product type or A or B, then add those products to a collection.
Why? We tried to build an automated collection, but with the limited conditional options, we can’t use AND/OR. We’d also prefer to not have to manually build the collection either, so I’ve been tasked with seeing if I can build a flow for it.
tag:tag-testing AND {{shop.gender.value}}:Mens AND product_type:Shirt OR product_type:T-Shirt
Based on the testing I’ve done, the flow does not ‘like’ this part: {{shop.gender.value}}:Mens - I suspect I’ve built this part of the query incorrectly, and that I don’t know how to ask it to be equal to Mens.
And the query without that segment works perfectly:
tag:tag-testing AND product_type:Shirt OR product_type:T-Shirt
Any assitance that could be provided to help me correctly match the metafield gender and having that equal a supplied term, would be greatly appreciated.
My intial query of tag:tag-testing AND (product_type:Shirt OR product_type:T-Shirt) works though. It only fails when I add the query to check the gender metafield, leading me to believe I’ve built that segment wrong.
Naturally, this flow only runs when a qualifying product has an inventory change, whereas, I’d like to ability to schedule this, or dictate specifically when I want it to run.
When setting up the trigger, these are two of my options:
If the initial query on the “Get product data” action of tag:tag-testing AND (product_type:Shirt OR product_type:T-Shirt) works enough to filter down the list of products returned then it may be easier to continu into a “For each” loop and then iterates each through add a subsequent condition that evaluates the returned data for the desired metafield value (see example) before the “Add product to a collection” action. While less efficient, using the variable picker in the condition may be a more user-friendly approach to defining the metafield and value than having to figure out how to compose the query. You can then branch multiple conditions (and subsequent loops and actions) off the “Get product data” action for each metafield value and collection you care about.
Ideally, I don’t want to change the trigger as I want to dictate when the flow runs. As for the required for each loop, I’m unsure at where to insert that into the flow. Are you able to help me with that part?
I don’t think you want to be getting gender from the shop object. You should get it from Product > metafields - it will prompt you for the namespace and key of that metafield.
The “For each” loop would go after the “Get product data” to cycle through each of the products returned. Then you can check for the metafield value and perform the desired action. As Kalen said, this approach is limited to 100 products at a time.
We’re back form the weekend, thanks for your paitence. I tried adding the For each loop after the get product data call, and it really dosen’t seem to like my metafield much: