2

I want to generate a list of events that are related to a specific festival and that are related to a specific category. This goal sits alongside some others that are inspiring me to attempt this in a single template and to do so via building params that are then passed to Craft entries tag. Using Craft 3.

First the base params - these return a fine result.

{# Set base criteria for event query #}
{% set params = {
    section : 'events',
    orderBy : 'eventStartDateTime asc',
    relatedTo: [
        { element: entry.id }
    ],
    limit: null
} %}

Next here are the params to try and get the events associated with a specific festival entry and that are related to a specific category.

{# Segment 4 is about categories #}
{% if craft.app.request.getSegment(4) %}
    {# segment 4 is the category slug #}
    {% set cat = craft.app.request.getSegment(4) %}
    {% set relationParam = {
        relatedTo: ['and',
            { targetElement: cat },
            { element: entry.id }
        ]
    }%}  

    {% set params = params|merge(relationParam) %}
{% endif %} 

What I am seeing in this second scenario is I am not getting results filtered by the category. Feel like I am close but missing something, likely fundamental.

1

I think the answer you’re looking for is here.

TL;DR:

relatedTo method accepts a CategoryModel, not the title(slug) of a category.

|improve this answer|||||
  • Thanks that seemed to do the trick. Had a feeling was missing something fundamental. – SethG Jan 28 '18 at 20:40

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.