I have a section with a Super Table field, each "row" of which contains a date field. I am looking for a way to query for entries where one of the rows contains a future date.
1 Answer
It's basically the same as Find entries that use a specific block in their Matrix field?
You can use the base query and left join your Super Table content row
{% set entries = craft
.entries()
.section(['your-section'])
.leftJoin('{{%supertableblocks}} as supertableblocks', '[[supertableblocks.ownerId]] = [[entries.id]]')
.leftJoin('{{%stc_content}} as stc_content', '[[stc_content.elementId]] = [[supertableblocks.id]]')
.andWhere(['>=', 'stc_content.field_date', entry.date|date('atom')])
.groupBy('supertableblocks.ownerId')
.all()
%}
Note: this is untested, maybe you need certain modifications it should just be some kind of guidance. Please keep in mind to replace your actual table and field names. I just used stc_content
as a demonstration as well as stc_content.field_date
-
great thank you, I had not seen the tables created by the plugin. Thanks it works now Aug 20, 2018 at 8:57
-
I get a SQL error when setting
groupBy
that says it's incompatible with MySql 5.7'ssql_mode=only_full_group_by
setting. Any way to modify to avoid the error?– kmgdevDec 1, 2019 at 1:24