0

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

  • Take a look at https://tighten.co/blog/craft-cms-building-complex-queries-by-extending-the-elementcriteriamodel and https://github.com/tightenco/craft-build-query for info on building more direct queries from Twig. – Dalton Rooney Sep 04 '19 at 04:27
  • Looked here https://craftcms.stackexchange.com/questions/21961/how-to-check-for-a-value-or-null-on-custom-enddate-field-using-yii-syntax-when-c to no avail. The answer provided there does not work... Braking this up into two queries for now. Any further suggestions welcome. – Document Services Sep 06 '19 at 00:08

0 Answers0