<p>These are simply low level operations you can do to more specifically filter the elements that should be returned. It is generally more common to use them in plugins/modules than in Twig templates, but the use-cases are numerous. A few trivial examples are below.</p>
<pre><code>{{ set entries = craft.entries.where(['authorId', 1]).all() }}

{{ set entries = craft.entries.where(['in', 'authorId', [1, 2, 3]]).all() }}

{{ set entries = craft.entries.where(['&gt;=', 'dateCreated', '2021-01-01']).all() }}

{{ set entries = craft.entries.where(['like', 'title', 'prefix%']).all() }}
</code></pre>
<p>Detailed docs for <code>where</code> and other DB query parameters can be found here:
<a href="https://www.yiiframework.com/doc/guide/2.0/en/db-query-builder#where" rel="nofollow noreferrer">https://www.yiiframework.com/doc/guide/2.0/en/db-query-builder#where</a></p>

CC BY-SA 4.0
2021-01-28T16:46:20.887Z
2021-01-29T08:39:09.910Z
2021-01-29T08:39:09.910Z
Ben Croker
<p>In Craft docs <a href="https://craftcms.com/docs/3.x/element-queries.html#advanced-element-queries" rel="nofollow noreferrer">element queries article</a>, there is section &quot;advanced element queries&quot;, with methods like <code>where</code>, <code>groupBy</code> etc.</p>
<p>What are example use cases of these methods in Twig templates or PHP modules?</p>

<elementquery>
Advanced Element Queries - example uses
# Advanced Element Queries - example uses

(Asked by: username_0 on 2021-01-25)

In Craft docs [element queries article](https://craftcms.com/docs/3.x/element-queries.html#advanced-element-queries), there is section "advanced element queries", with methods like `where`, `groupBy` etc.

What are example use cases of these methods in Twig templates or PHP modules?

**Tags:** elementquery


---

## 1 answers

### Answer by username_1 on 2021-01-28. Score: 4 | Accepted answer

These are simply low level operations you can do to more specifically filter the elements that should be returned. It is generally more common to use them in plugins/modules than in Twig templates, but the use-cases are numerous. A few trivial examples are below.
{{ set entries = craft.entries.where(['authorId', 1]).all() }}

{{ set entries = craft.entries.where(['in', 'authorId', [1, 2, 3]]).all() }}

{{ set entries = craft.entries.where(['>=', 'dateCreated', '2021-01-01']).all() }}

{{ set entries = craft.entries.where(['like', 'title', 'prefix%']).all() }}

Detailed docs for where and other DB query parameters can be found here:
https://www.yiiframework.com/doc/guide/2.0/en/db-query-builder#where


---

