Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-11-13T10:42:43.253Z
Answers.Text: 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.
Answers.UserDisplayName: Tom De Smet
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-11-13T10:45:15.263Z
Answers.Text: Thanks it works, Can I pass array in targetElement?
Answers.UserDisplayName: Kantesh Hotchandani
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-11-13T10:53:09.200Z
Answers.Text: 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() %}
Answers.UserDisplayName: Kantesh Hotchandani
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-11-13T10:15:42.833Z
Answers.LastActivityDate: 2017-11-13T11:16:00.773Z
Answers.LastEditDate: 2017-11-13T11:16:00.773Z
Answers.UserDisplayName: Robin Schambach
Body: <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>
  
Tags: <categories><craft3><category><craft.entries>
Title: How to load entries with a certain category only?
ThreadText: # 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](https://craftcms.com/docs/templating/elementcriteriamodel)
  
  > **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() %}  
  
  ---
  
  