Answers.Body: <p>Okay, doesn't seem to be the most elegant but the only way I could achieve this was by carrying out the entries criteria query within my <code>$fields</code> loop. So, for example:</p>
  
  <pre><code>$entries = [];
  
  foreach ($fields AS $field) {
      $criteria = craft()-&gt;elements-&gt;getCriteria(ElementType::Entry);
      $criteria-&gt;limit = NULL;
      $criteria-&gt;$field = ':notempty:';
      $tmpEntries = $criteria-&gt;find();
  
      $entries = array_merge($entries,$tmpEntries);
  }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-09-05T14:30:09.067Z
Answers.LastActivityDate: 2017-09-05T18:19:23.477Z
Answers.LastEditDate: 2017-09-05T18:19:23.477Z
Answers.UserDisplayName: Cole Henley
Body: <p>I'm trying to use the Element Criteria Model to retrieve all entries where value <code>X</code> or value <code>Y</code> is not null?</p>
  
  <p>I can get all entries where values and X <em>and</em> Y are not empty but not sure how to achieve this with either X <em>or</em> Y being not empty. any thoughts?</p>
  
  <pre><code>$criteria = craft()-&gt;elements-&gt;getCriteria(ElementType::Entry);
  $criteria-&gt;limit = NULL;
  
  foreach ($fields AS $field) {
      $criteria-&gt;$field = ':notempty:';
  }
  
  $entries = $criteria-&gt;find();
  </code></pre>
  
  <p>This is what I have for <em>AND</em> but not sure how best to go about achieving the same query for <em>OR</em>.</p>
  
  <p>An equivalent SQL query would be something along lines of <code>WHERE (X IS NOT NULL &amp;&amp; X &lt;&gt; '') OR (Y IS NOT NULL &amp;&amp; Y &lt;&gt; '')</code></p>
  
Tags: <plugin-development><elementcriteriamodel>
Title: Element Criteria Model: filtering by empty values
ThreadText: # Element Criteria Model: filtering by empty values
  
  (Asked by: username_0 on 2017-09-05)
  
  I'm trying to use the Element Criteria Model to retrieve all entries where value `X` or value `Y` is not null?
  
  I can get all entries where values and X *and* Y are not empty but not sure how to achieve this with either X *or* Y being not empty. any thoughts?
  
  ```
  $criteria = craft()->elements->getCriteria(ElementType::Entry);
  $criteria->limit = NULL;
  
  foreach ($fields AS $field) {
      $criteria->$field = ':notempty:';
  }
  
  $entries = $criteria->find();
  
  ```
  
  This is what I have for *AND* but not sure how best to go about achieving the same query for *OR*.
  
  An equivalent SQL query would be something along lines of `WHERE (X IS NOT NULL && X <> '') OR (Y IS NOT NULL && Y <> '')`
  
  **Tags:** plugin-development, elementcriteriamodel
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2017-09-05. Score: 2
  
  Okay, doesn't seem to be the most elegant but the only way I could achieve this was by carrying out the entries criteria query within my `$fields` loop. So, for example:
  
  ```
  $entries = [];
  
  foreach ($fields AS $field) {
      $criteria = craft()->elements->getCriteria(ElementType::Entry);
      $criteria->limit = NULL;
      $criteria->$field = ':notempty:';
      $tmpEntries = $criteria->find();
  
      $entries = array_merge($entries,$tmpEntries);
  }
  
  ```
  
  
  ---
  
  