I'm trying to set up an archive page by passing dates in the URL to the entries search parameter to show events from a specific month. The eventstart is a custom date field. If I enter numbers i.e. 2017-11 in the search parameter it works but the URL segments don't seem to parse.

Thanks in advance.

{% set year = craft.request.segment(3) %}
{% set month = craft.request.segment(4) %}

{% set entries = craft.entries.section('calendar').search('eventstart:"year-month)"') %}

{% for entry in entries %}
    <h3><a href="{{ entry.url }}">{{ entry.title }}</a></h3>
{% endfor %}

You'd need to use Twig's string concatenation in order to do this with the ~ operator.

{% set entries = craft.entries.section('calendar').search('eventstart:' ~ year ~ '-' ~ month) %}

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.