Advanced Query help - get product with publication date minus today date <= 30

  • I run a bookshop.

  • Each book has a custom metafield data point for the publication date of the book (this is when the book was published by the publishers, not published to Shopify)

  • I would like to write an advanced query for get product data that filter products that match the following:

metafields.custom.book_publication_date - today’s date <= 30.

Could someone help please?

I don’t know how much I can help with flow but I can try getting this with liquid.

You basically want all books that have been published within a month or less. What do you plan to do with the products though?

Thanks for your response.

The flow will tag products whose publication date is within 30 days of today and remove the tag on products whose publication date is not within 30 days of today.

I’ve built the flow, I just need help with the advanced query on the get product data step.

rather than iterate through the 5,000 plus products we have, I thought it better to apply a advanced query filter to the get product data step.

can you help with that query please?

Hi @benalexanderjon. :waving_hand: You provided additional context in another thread that you’re looking to query by a metafield value. The query on the Get product data action only accepts filters supported by the Admin API. Unfortunately, querying by metafield value is not supported.

Correction: According to these docs it may be possible to query by metafield value but I’m not sure how to express that query in Liquid syntax in Flow.

Also, please stop starting new threads and instead use the original thread, as it makes it harder to support you with a proper answer. :sweat_smile:

Do you know anyone who could help with writing the query?

Sorry, I’m not familiar with these query options. It might be that the lightly documented “query by metafield value” option doesn’t support date types or ranges (such a < or >). You might try using GraphiQL to test out a few queries and see if it works using other metafields, =, or other combinations.

To follow up here, date metafields are not queryable at all. So if this metafield is a date type you cannot yet query. You could potentially store the data as a string, which is supported. However, string values cannot be used with < or >, since they aren’t numbers. Numbers, like dates, are also not queryable yet. Just to make this clear, this isn’t a Flow limitation but one with metafields.

So to do your use case, you likely need to workaround the fact that you can only query dates if they are strings and exactly match your query.