1

In Craft docs element queries article, 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?

2

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.