I’m trying to do something, the answer to which should be as simple as searching a Matrix field value but that’s not working for reasons I can’t fathom.
Setup
- I have a Matrix field called
programme
. - It includes a block type called
item
. - That block type has a field with a handle of
od
. - I have a test case entry that has 4
item
blocks in it. - All 4 of these blocks have a value in their
od
field but I need to check for scenarios where some or all of those blocks have that field empty.
So, I’m querying:
{% set talks = entry.programme.type('item').all() %}
{% set odTalks = entry.programme.type('item').od(':notempty:').all() %}
…and then checking that works with:
<pre>
talks: {{ talks|length }}
odTalks: {{ odTalks|length }}
</pre>
…and the result I’m getting is:
talks: 4
odTalks: 0
I’ve tried other search values I know should work with the specific entry’s values, including regex strings. I've tried searching other fields in the block, and nothing works.
What could I be doing wrong?
Would be a shame to have to do something like this just to compare the lengths of talks
and odTalks
and act accordingly…
{% set odTalks = 0 %}
{% for talk in talks %}
{% if talk.od is not empty %}
{% set odTalks = odTalks + 1 %}
{% endif %}
{% endfor %}
…even though that works and produces the expected:
talks: 4
odTalks: 4
od
?