1

After spending a lot of time solving this for myself I thought I'd share it. In my Craft 2 template I had this query:

{% set result = craft.entries({
    section: 'events',
    eventDate: ['and', '<' ~ now.w3c(), '> ' ~ now | date_modify('-6 days')],
    results: ':notempty:',
    order: 'eventDate desc',
    with: ['imageGallery'],
    limit: 3
}) %}
3

My Craft 3 version is:

{% set result = craft.entries()
    .section('events')
    .eventDate( ['and', '<' ~ now|atom, '>' ~ now|date_modify('-6 days')|atom ] )
    .results(':notempty:')
    .orderBy('eventDate desc')
    .limit(3)
    .with(['imageGallery'])
    .all()
%}

Note the extra |atom after the date_modify('-6 days')

  • The atom filter would work too, so just simplified your example to use that. Also worth noting that batch-setting parameters is still supported, though the chain syntax you’ve switched to is better (gives the query a chance to do normalization on the values). – Brandon Kelly Aug 13 '18 at 21:34
  • I seem to remember being advised to use the batch setting method in preference in a past SE answer. This caused me some confusion switching my existing Craft 2 code to Craft 3 as all the example code uses the chain syntax. – Paul Frost Aug 14 '18 at 7:47
  • It was faster to use the batch method in Craft 2; in Craft 3 it’s a wash either way. – Brandon Kelly Aug 14 '18 at 11:53

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.