5.x Filtering against a field that's shared across many entry types is cumbersome #16892
-
If you want to fetch multiple types in a single query & filter against a field that's shared across them, it's more cumbersome in 5.x than in 4.x. Mostly because there's no longer a single column name to target (instead theres a uid per type). The code below demonstrates the issue: In 4.x:
in 5.x:
I understand the reasons for that, and presumably there's not much to be done about it so I'm mostly wondering if this can be abstracted/if we can get a method/service or something to assist with it. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Most field types provide their own element query params that simplify filtering results by them. For example, if this is a Plain Text field, you could do: $elementQuery->myFieldHandle('not abc');
// or:
$elementQuery->myFieldHandle(['not', 'abc']); And as of Craft 5.6, you can now refer to custom field handles within conditions passed to $elementQuery->andWhere(['not', ['myFieldHandle' => 'abc']]); (Same goes for |
Beta Was this translation helpful? Give feedback.
Most field types provide their own element query params that simplify filtering results by them.
For example, if this is a Plain Text field, you could do:
And as of Craft 5.6, you can now refer to custom field handles within conditions passed to
where()
(et al.), and they will automatically get replaced with references to the individual sub-JSON values.(Same goes for
orderBy
andselect
methods - #16157.)