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.

2 Answers 2

2

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
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

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.