<p>This should do what you are looking for:</p>

<pre><code>{% set category = craft.categories.slug('family') %}
{% set entries = craft.entries.section('images').relatedTo(category).find() %}

{# If there are any entries, loop through them #}
{% if entries | length %}

    {# For each entry we find, do this #}
    {% for entry in entries %}
        &lt;p&gt;{{ entry.title }}&lt;/p&gt;
    {% endfor %}

{% endif %}
</code></pre>

<p>So we are creating a variable called category, in which you set the category you want to get the list of related entries from.</p>

<p>Next we set a variable called entries, which checks to see if there are any entries in the Image section that relate to the category we set.</p>

<p>It then loops through the entries that we find (if there are any).</p>

<p><strong>EDIT</strong></p>

<p>More than one category group might have the Family category. To get round this you can target a specific category group when we set the category variable:</p>

<pre><code>{% set category = craft.categories.group('categoryGroup').slug('family') %}
</code></pre>

CC BY-SA 3.0
2016-01-07T23:37:37.080Z
This makes much more sense now. I think the [docs could make it a little more explicit](https://craftcms.com/docs/relations#the-relatedTo-param) in it's examples that you're passing an object as parameters, especially for those of us new to programming (I'm sure there are going to be lots of us as Craft grows!)
Rob
CC BY-SA 4.0
2018-05-07T17:41:14.180Z
For those coming here via search and using Craft 3, make sure you add `.one()` when retrieving the category, e.g. `{% set category = craft.categories.group('categoryGroup').slug('family').one() %}`, otherwise you won't get any entries matching.
Nate Beaty
CC BY-SA 3.0
2014-10-14T15:11:41.460Z
Hmm, my problem with that is there may be more than category group that has a category of 'family' in it. Is there a way to specify both category group and category? Thanks btw!!!
John
CC BY-SA 3.0
2014-10-14T15:17:56.197Z
Sure, no problem, I have edited my answer. Just swap out categoryGroup with the category group you want to target.
Jamie Wade
CC BY-SA 3.0
2014-10-14T13:52:06.703Z
2014-10-14T15:17:19.187Z
2014-10-14T15:17:19.187Z
Jamie Wade
<p>So, i have a channel called images and a couple of category groups one of which is called "images" which has categories called family, animals, individuals in it.</p>

<p>So, i just want to grab the entries that have one of those categories assigned / related to them.</p>

<p>Figured something like this would do it</p>

<pre><code>    {% for entry in craft.entries.section('images').relatedTo('photography').find('family') %}
        &lt;h3&gt;{{ entry.title }}&lt;/h3&gt;
    {% endfor %}
</code></pre>

<p>But i figured wrong! Any ideas would be gratefully received!</p>

<entries><categories>
Get entries which have a certain category assigned to them
# Get entries which have a certain category assigned to them

(Asked by: username_0 on 2014-10-14)

So, i have a channel called images and a couple of category groups one of which is called "images" which has categories called family, animals, individuals in it.
So, i just want to grab the entries that have one of those categories assigned / related to them.
Figured something like this would do it
    {% for entry in craft.entries.section('images').relatedTo('photography').find('family') %}
        {{ entry.title }}
    {% endfor %}

But i figured wrong! Any ideas would be gratefully received!

**Tags:** entries, categories


---

## 1 answers

### Answer by username_1 on 2014-10-14. Score: 15 | Accepted answer

This should do what you are looking for:
{% set category = craft.categories.slug('family') %}
{% set entries = craft.entries.section('images').relatedTo(category).find() %}

{# If there are any entries, loop through them #}
{% if entries | length %}

    {# For each entry we find, do this #}
    {% for entry in entries %}
        {{ entry.title }}
    {% endfor %}

{% endif %}

So we are creating a variable called category, in which you set the category you want to get the list of related entries from.
Next we set a variable called entries, which checks to see if there are any entries in the Image section that relate to the category we set.
It then loops through the entries that we find (if there are any).
EDIT
More than one category group might have the Family category. To get round this you can target a specific category group when we set the category variable:
{% set category = craft.categories.group('categoryGroup').slug('family') %}

> **Comments:**
> **username_0**: Hmm, my problem with that is there may be more than category group that has a category of 'family' in it. Is there a way to specify both category group and category? Thanks btw!!!  
> **username_1**: Sure, no problem, I have edited my answer. Just swap out categoryGroup with the category group you want to target.  
> **username_2**: This makes much more sense now. I think the [docs could make it a little more explicit](https://craftcms.com/docs/relations#the-relatedTo-param) in it's examples that you're passing an object as parameters, especially for those of us new to programming (I'm sure there are going to be lots of us as Craft grows!)  
> **username_3**: For those coming here via search and using Craft 3, make sure you add `.one()` when retrieving the category, e.g. `{% set category = craft.categories.group('categoryGroup').slug('family').one() %}`, otherwise you won't get any entries matching.  

---

