2

On a website upgraded to Craft 3 - having issues pulling events by date.

Error Is:

Calling unknown method: craft\behaviors\ElementQueryBehavior::eventDate()

The Error occurs on the last line of my code below. I'm done alot of searching but unable to find the correct method I should be using now.

    {% if (category is defined) and (category is not empty) %}
    {% set params = { section: 'events', orderBy: 'eventDate', relatedTo: category } %}
    {% else %}
    {% set params = { section: 'events', orderBy: 'eventDate' } %}
    {% endif %}          
    {% set j = 0 %}
    {# Retrieve all of the events for the month, and group them by day #}
    {% set groupedEvents = craft.entries(params).eventDate('and', '>= ' ~ startdate, '<= ' ~ enddate) | group('eventDate|date("Y-m-d")') %}

UPDATE Ok think found the issue - needed square brackets.

{% set groupedEvents = craft.entries(params).eventDate(['and', '>= ' ~ startdate, '<= ' ~ enddate]) | group('eventDate|date("Y-m-d")') %}
  • Glad you got it sorted! Would you mind adding that as an official answer in case it ends up helping someone in the future? – Brad Bell Jun 14 '18 at 23:34
2

Was missing the square brackets

{% set groupedEvents = craft.entries(params).eventDate(['and', '>= ' ~ startdate, '<= ' ~ enddate]) | group('eventDate|date("Y-m-d")') %}
  • 100%. Need to wait 18 hours before I can accept that as answer. – mmc501 Jun 15 '18 at 22:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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