I’m using a structure for creating new pages and navigation. In this structure there are multiple entry types where one is used for creating category pages. Here a user can add some content and select a category that will be used to load projects that are related to it.

In my template I'm using this code to do this:

{% set category = entry.projectCategory.first().slug %}
{% set params = {
        section: 'projects',
        relatedTo: category
} %}
{% set projectEntries = craft.entries(params) %}

    <h1>{{ category }}</h1>

{% for projectEntry in projectEntries %}
            <a href="{{ projectEntry.url }}">
                <div class="index-image">
                    {% set image = projectEntry.featuredImage.first() %}{% if image %}<img src="{{ image.getUrl('fullImage') }}" alt="{{ image.title }}">{% endif %}
                <div class="index-title">
                    <h2>{{ projectEntry.title }}</h2>
{% endfor %}

First I'm getting the category slug that was selected for this category page. After that I'm setting up my parameters for getting projects (this is another section) that are related to that category.

Before it worked perfectly fine when I had put in a "static" category (so not using the category variable) but when I tried to push the selected category the whole thing stopped working. Even going back to my original code that worked doesn't load any projects.

If I remove the "relatedTo" argument it loads all projects just fine.

Also the slug is perfectly shown in the H1 tag.

Any ideas?

1 Answer 1


You are so close! All you need to do is to remove the ’.slug’, because that is what the param is expecting.

  • Nice, perfect! This is my first Craft/Twig project so these little things pop up a lot haha. Sep 2, 2017 at 8:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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