2

I'm using the multidate field plugin, which is excellent at presenting dates but I need to return entries based on testing the first date in there. I typically test with the entries loop, like so:

{% if product.dates.dates[0] | date('U') > now | date ('U') %}

but would prefer to only get entries fitting that criteria in the first place. Is there any way to fetch entries according to the first value in a an array like this?

{% set products = craft.commerce.products.dates(somehow only test the first value in the dates array here) %}

The field looks something like this:

dates [ // this is the custom field name
    dates [ // this is the dates array within the custom field
        [0] // this is the date object I want to test against
        [1]
        [2]
    ]
]

1 Answer 1

1

That plugin doesn't provide a custom element type, so there's no way for it to have a chance to modify the main elements query when fetching the data.

In its existing form, you'll have to do the filtering on the Twig side like you're doing to grab the one you're looking for.

1
  • I feared that was the case. No worries. Mar 16, 2017 at 8:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.