1

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
  • The solution of the previous comment did workout for me, just notice that the blocks should be called like this: stc_XXX field_XXX
    – HairyMike
    Nov 18, 2021 at 9:18

1 Answer 1

3

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

2
  • 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's sql_mode=only_full_group_by setting. Any way to modify to avoid the error?
    – kmgdev
    Dec 1, 2019 at 1:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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