Body: <p>I'm looking to write advanced nested search queries in Craft.</p>
  
  <p>For example, below I'm looking to find results that have a <code>featuredContent</code> value of 1 <strong>and</strong> an <code>endDate</code> after today <strong>or</strong> empty. In psuedo code, <code>(this == 1 AND (that = foo OR that = bar )</code>.</p>
  
  <p><code>{% set params = {
    section : 'sectionName',
    orderBy : 'startDate asc',
    featuredContent : "1",
    endDate : "&gt;= " ~ now|date('Y-m-d') ~ ' OR :empty:'
  } %}</code></p>
  
  <p><code>{% set results = craft.entries(params).all() %}</code></p>
  
  <p>Sadly, this doesn't work. Do I need to write this as a <code>search</code> function? If so, how?</p>
  
  <p>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.. </p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-09-04T04:27:38.397Z
Comments.Text: 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.
Comments.UserDisplayName: Dalton Rooney
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-09-06T00:08:05.507Z
Comments.Text: 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.
Comments.UserDisplayName: Document Services
Tags: <entries><search>
Title: Advanced Entry Queries
ThreadText: # Advanced Entry Queries
  
  (Asked by: username_0 on 2019-09-04)
  
  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..
  
  **Tags:** entries, search
  
  > **Comments:**
  > **username_1**: 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.  
  > **username_0**: 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.  
  
  ---
  
  ## 0 answers
  
  