I'm looking to write advanced nested search queries in Craft.

For example, below I'm looking to find results that have a featuredContent value of 1 and an endDate after today or empty. In psuedo code, (this == 1 AND (that = foo OR that = bar ).

{% set params = { section : 'sectionName', orderBy : 'startDate asc', featuredContent : "1", endDate : ">= " ~ now|date('Y-m-d') ~ ' OR :empty:' } %}

{% set results = craft.entries(params).all() %}

Sadly, this doesn't work. Do I need to write this as a search function? If so, how?

A related question might be: is there a way to directly use MySQL WHERE queries to return entries via TWIG? This would be super helpful at times..


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.