I'll import (event) entries with feedme in craftcms 2 from an API who I'll can't change. The api gives the startdate off the events in a dateTime object. The allDay events have a date without time. Because the api also names those date elements different (start/dateTime, start/date) I'll have to import the data separate in to two fields for start and for end.

The question is how I'll get all those events (entries) together ordered by date? From the current date to the currentdate plus 6 months. The entries with the allDay date have an empty field for startDate and endDate and visa versa.

This is what I'll have but that didn't work.

  'api/calendar' => function() {

            // Fetch global set 'agenda'

            return [
                'elementType' => 'Entry',
                'criteria' => [
                    'limit' => 0,
                    'startDate' => ['and', '>=' . date('U') . ""],
                    'endDate' => ['and', '<=' . date('U', strtotime("+6 months")) . ""],

                    'order'     => 'startDatum asc'

Perhaps you could use the Preparse Field plugin, so that you only need to deal with one field. That would make the query easier. https://plugins.craftcms.com/preparse-field

  • Thanx, didn't know that plugin, searched for something like that but couldn't find anything. This solved my problem! – Maarten Heideman Jun 18 '20 at 19:26
  • Happy to hear it worked out! – KSP Jun 18 '20 at 20:52

Your Answer

