3

I've got a category group called allcategories, inside of this is two categories called design and photo.

I'm trying to filter all entries in the section projects by the category `photo' but none of my permutations are working :(

<section class="index">

    {% set category = craft.categories.group('allcategories').find('photos') %}
    {% set projects = craft.entries.section('projects').relatedTo(category).find() %}

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

</section>
5

Your mistake is in getting the category. Instead of what you have try:

{% set category = craft.categories.group('allcategories').slug('photos').find() %}

Getting elements in Craft use ElementCriteriaModel and find(), first(), last(), &c. do not accept any parameters (though nth() is an exception to this). So you need to search by other fields in the element as per the docs.

You may also want to make sure that the slug of the category group is not camel case (allCategories as opposed to allcategories).

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.