Answers.Body: <p>Filtering a list of entries is quite simple. Here's an example from one of our sites:</p>
  
  <pre><code>{% for job in craft.entries({
      section: 'jobs',
      applicationsClose: "&gt;= " ~ (now|date('Y-m-d')),
      internalExternal: 'external',
  }) %}
  
      ...
  
  {% endfor %}
  </code></pre>
  
  <p>Here we define the section we're looking in and then filter by two custom fields: <code>applicationsClose</code> and <code>internalExternal</code>.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-05-08T08:50:44.493Z
Answers.Text: Should be the better answer since there is no searching involved.
Answers.UserDisplayName: biko
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-25T04:30:24.870Z
Answers.LastActivityDate: 2018-06-25T04:30:24.870Z
Answers.UserDisplayName: Simon East
Answers.Body: <pre><code>{% set featuredProducts = craft.entries
      .section('sectionName')
      .featured(true)
      .all() %}
  </code></pre>
  <p>Where <code>sectionName</code> is the name of your section;</p>
  <p><code>featured</code> is your featured field handle;</p>
  <p><code>true</code> is the value you want to query the lightswitch fields for.</p>
  <p>Each field type in the Craft docs has an element query example, e.g. <a href="https://craftcms.com/docs/3.x/lightswitch-fields.html#querying-elements-with-lightswitch-fields" rel="nofollow noreferrer">lightswitch fields</a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-04-08T10:35:43.203Z
Answers.LastActivityDate: 2021-09-12T03:11:47.127Z
Answers.LastEditDate: 2021-09-12T03:11:47.127Z
Answers.UserDisplayName: DimaS
Answers.Body: <p>Another way for Craft 3</p>
  <pre><code>{# Create an entry query with the 'section' and 'limit' parameters #}
  {% set entryQuery = craft.entries()
      .section('Blog')
      .search('entryColor:green')
      .limit(10) %}
                  
  {# Fetch the entries. #}
  {% set entries = entryQuery.all() %}
  
  {% if entries|length &gt; 0 %}
      {% for entry in entries %}
          {{ entry.title }}
      {% endfor %}
  {% endif %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-10-11T21:09:47.997Z
Answers.LastActivityDate: 2020-12-02T21:20:56.380Z
Answers.LastEditDate: 2020-12-02T21:20:56.380Z
Answers.UserDisplayName: Damon
Answers.Body: <p>Use the <a href="https://craftcms.com/docs/searching" rel="noreferrer">search parameter</a> in the <code>craft.entries</code> model:</p>
  
  <pre><code>{% for entry in craft.entries.section('Blog').search('featuredFieldName:1') %}
  
      {# Entry Code #}
  
  {% endfor %}
  </code></pre>
  
  <p>To filter by a specific text snippet:</p>
  
  <pre><code>{% for entry in craft.entries.section('Blog').search('entryColor:"green"') %}
  
      {# Entry Code #}
  
  {% endfor %}
  </code></pre>
  
  <p>You can create more complex search queries as well, see the documentation for more info. But the basic idea is to use <code>.search()</code>, then enter your search query in quotes.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-09-14T21:58:58.067Z
Answers.Text: While the `search` query param _will_ work for many field values, it ultimately gets parsed back into an explicit `ElementQuery`. The recommended way to filter by custom field data (or built-in Element properties) is to use the chaining syntax demonstrated in other answers; in addition to allowing for a wider variety of filtering strategies, it tends to be much easier to distinguish syntax issues (Twig and Search) from search index issues.
Answers.UserDisplayName: August Miller
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-05-27T09:24:09.453Z
Answers.LastActivityDate: 2016-05-27T09:24:09.453Z
Answers.UserDisplayName: kmgdev
Body: <p>How do I filter a list of entries by the value of a field? For example, if I have a lightswitch field called "Featured", how do I output just the featured entries?</p>
  
Tags: <entries><search><filtering>
Title: Filter Entries by Field Value
ThreadText: # Filter Entries by Field Value
  
  (Asked by: username_0 on 2016-05-27)
  
  How do I filter a list of entries by the value of a field? For example, if I have a lightswitch field called "Featured", how do I output just the featured entries?
  
  **Tags:** entries, search, filtering
  
  
  ---
  
  ## 4 answers
  
  ### Answer by username_0 on 2016-05-27. Score: 8 | Accepted answer
  
  Use the [search parameter](https://craftcms.com/docs/searching) in the `craft.entries` model:
  
  ```
  {% for entry in craft.entries.section('Blog').search('featuredFieldName:1') %}
  
      {# Entry Code #}
  
  {% endfor %}
  
  ```
  
  To filter by a specific text snippet:
  
  ```
  {% for entry in craft.entries.section('Blog').search('entryColor:"green"') %}
  
      {# Entry Code #}
  
  {% endfor %}
  
  ```
  
  You can create more complex search queries as well, see the documentation for more info. But the basic idea is to use `.search()`, then enter your search query in quotes.
  
  > **Comments:**
  > **username_5**: While the `search` query param _will_ work for many field values, it ultimately gets parsed back into an explicit `ElementQuery`. The recommended way to filter by custom field data (or built-in Element properties) is to use the chaining syntax demonstrated in other answers; in addition to allowing for a wider variety of filtering strategies, it tends to be much easier to distinguish syntax issues (Twig and Search) from search index issues.  
  
  ---
  
  ### Answer by username_1 on 2018-06-25. Score: 12
  
  Filtering a list of entries is quite simple. Here's an example from one of our sites:
  
  ```
  {% for job in craft.entries({
      section: 'jobs',
      applicationsClose: ">= " ~ (now|date('Y-m-d')),
      internalExternal: 'external',
  }) %}
  
      ...
  
  {% endfor %}
  
  ```
  
  Here we define the section we're looking in and then filter by two custom fields: `applicationsClose` and `internalExternal`.
  
  > **Comments:**
  > **username_2**: Should be the better answer since there is no searching involved.  
  
  ---
  
  ### Answer by username_3 on 2021-04-08. Score: 8
  
  ```
  {% set featuredProducts = craft.entries
      .section('sectionName')
      .featured(true)
      .all() %}
  
  ```
  
  Where `sectionName` is the name of your section;
  
  `featured` is your featured field handle;
  
  `true` is the value you want to query the lightswitch fields for.
  
  Each field type in the Craft docs has an element query example, e.g. [lightswitch fields](https://craftcms.com/docs/3.x/lightswitch-fields.html#querying-elements-with-lightswitch-fields)
  
  
  ---
  
  ### Answer by username_4 on 2018-10-11. Score: 3
  
  Another way for Craft 3
  
  ```
  {# Create an entry query with the 'section' and 'limit' parameters #}
  {% set entryQuery = craft.entries()
      .section('Blog')
      .search('entryColor:green')
      .limit(10) %}
                  
  {# Fetch the entries. #}
  {% set entries = entryQuery.all() %}
  
  {% if entries|length > 0 %}
      {% for entry in entries %}
          {{ entry.title }}
      {% endfor %}
  {% endif %}
  
  ```
  
  
  ---
  
  