<p>You could use this, note: this is untested maybe you have to remove the <code>first()</code> or use <code>targetElement: category1.id</code></p>

<pre><code>{% set category1 = craft.categories.id(yourId).one() %}
{% set category2 = craft.categories.id(yourId2).one() %}
{% set news = craft.entries.all({
    section: 'news',
    relatedTo: [
        'and',
        { targetElement: category1.id },
        { targetElement: category2.id }
    ]
}) %}
</code></pre>

<p>You should read about that topic here <a href="https://craftcms.com/docs/templating/elementcriteriamodel" rel="nofollow noreferrer">click</a></p>

CC BY-SA 3.0
2017-11-13T10:42:43.253Z
I think you can pass the ID's of the categories directly into the related to parameter and add the source attribute pointed to the category field as well. Makes for a few lines less code.
Tom De Smet
CC BY-SA 3.0
2017-11-13T10:45:15.263Z
Thanks it works, Can I pass array in targetElement?
Kantesh Hotchandani
CC BY-SA 3.0
2017-11-13T10:53:09.200Z
Done some thing like this way                                                                                     {% set entries = craft.entries({
    section: 'news',
    orderBy: 'postDate desc',
    limit:3,
    relatedTo: [
        'or',
        { targetElement: entry.newsCategory.all() }
    ]
}).id('not '~entry.id).all() %}
Kantesh Hotchandani
CC BY-SA 3.0
2017-11-13T10:15:42.833Z
2017-11-13T11:16:00.773Z
2017-11-13T11:16:00.773Z
Robin Schambach
<p>I am trying to load entries from a section which have a category field with multiple values. Based on that, I want to show specific entries filtered by category.</p>

<p><strong>Example:</strong> I have a news section and I want to load sports and entertainment news only.</p>

<p>Help me on this, please.</p>

<categories><craft3><category><craft.entries>
How to load entries with a certain category only?
# How to load entries with a certain category only?

(Asked by: username_0 on 2017-11-13)

I am trying to load entries from a section which have a category field with multiple values. Based on that, I want to show specific entries filtered by category.

**Example:** I have a news section and I want to load sports and entertainment news only.

Help me on this, please.

**Tags:** categories, craft3, category, craft.entries

---

## 1 answers

### Answer by username_1 on 2017-11-13. Score: 1 | Accepted answer

You could use this, note: this is untested maybe you have to remove the first() or use targetElement: category1.id
{% set category1 = craft.categories.id(yourId).one() %}
{% set category2 = craft.categories.id(yourId2).one() %}
{% set news = craft.entries.all({
    section: 'news',
    relatedTo: [
        'and',
        { targetElement: category1.id },
        { targetElement: category2.id }
    ]
}) %}

You should read about that topic here click

> **Comments:**
> **username_2**: I think you can pass the ID's of the categories directly into the related to parameter and add the source attribute pointed to the category field as well. Makes for a few lines less code.  
> **username_0**: Thanks it works, Can I pass array in targetElement?  
> **username_0**: Done some thing like this way                                                                                     {% set entries = craft.entries({     section: 'news',     orderBy: 'postDate desc',     limit:3,     relatedTo: [         'or',         { targetElement: entry.newsCategory.all() }     ] }).id('not '~entry.id).all() %}  

---

