Answers.Body: <p>A workaround solution was to essentially do an criteria on the section, return all the records, use a conditional to find out which records have the same "parent ID" and ID", stores those in an array and then use the id criteria for the entry source.</p>
  
  <p>Something like:</p>
  
  <pre><code>$criteria = craft()-&gt;elements-&gt;getCriteria(ElementType::Entry);
  $criteria-&gt;section = 'theSection';
  $criteria-&gt;limit = null;
  $articles = $criteria-&gt;find();
  
  // For storing matching entries on the conditional below
  $ids = [];
  
  foreach ($entries as $entry)
  {
       if($entry-&gt;fieldParentId == $entry-&gt;fieldId)
       {
           array_push($ids, $entry-&gt;id);
       }
  }
  </code></pre>
  
  <p>This will then provide a list of ids that match the required criteria, which can then be used for a specific entry source.</p>
  
  <p>This has performance issues though, because you have to get the entire list of entries first each time.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-09-02T08:56:01.733Z
Answers.Text: So why don't you query for entries with the same columns from the beginning and return only the ids? You can transform the criteria model into a query and include normal `where` conditions. Otherwise you might run into performance issues sooner or later
Answers.UserDisplayName: Robin Schambach
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-09-12T07:41:19.673Z
Answers.Text: @RobinSchambach I'd agree that's a better way. We ended up changing the structure of the records, so we didn't have to do this in the end, but a query would be more performance friendly.
Answers.UserDisplayName: James White
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-09-02T08:35:00.810Z
Answers.LastActivityDate: 2018-09-02T08:35:00.810Z
Answers.UserDisplayName: James White
Body: <p>Is it possible with the modifyEntrySources hook to query a field value against another fields value? Example:</p>
  
  <p>Two fields are present on the entry section this hook targets</p>
  
  <ul>
  <li>fieldParentId</li>
  <li>fieldId</li>
  </ul>
  
  <p>I want to be able to query in the entry source definition if the <code>fieldParentId</code> is the same as the <code>fieldId</code> to return only those records in the entry list within Craft that match this. I'm not sure this is possible, or if there is a special syntax required within the <code>criteria</code> array to do it?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-08-30T13:47:57.750Z
Comments.Text: It is possible to do this with Craft 3 since you work with queries directly, you'll need an ugly work around with Craft 2 because you can't create such a condition via array by default, so you'll need to overwrite and extend more things
Comments.UserDisplayName: Robin Schambach
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-08-30T18:04:33.203Z
Comments.Text: I'm on Craft 2 for now. I ended up having to perform a ElementCriterialModel query and return  all entries in the section then in a foreach do a comparison with the two fields and return the ids that all matched to use in the entry source criteria. Not ideal but does the job.
Comments.UserDisplayName: James White
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-08-31T20:31:57.587Z
Comments.Text: @JamesWhite Could you add the solution you ended up on as an official answer? Might end up helping someone in the future.
Comments.UserDisplayName: Brad Bell
Tags: <elementcriteriamodel>
Title: modifyEntrySources hook, comparing two field values
ThreadText: # modifyEntrySources hook, comparing two field values
  
  (Asked by: username_0 on 2018-08-30)
  
  Is it possible with the modifyEntrySources hook to query a field value against another fields value? Example:
  
  Two fields are present on the entry section this hook targets
  
  * fieldParentId
  * fieldId
  
  I want to be able to query in the entry source definition if the `fieldParentId` is the same as the `fieldId` to return only those records in the entry list within Craft that match this. I'm not sure this is possible, or if there is a special syntax required within the `criteria` array to do it?
  
  **Tags:** elementcriteriamodel
  
  > **Comments:**
  > **username_1**: It is possible to do this with Craft 3 since you work with queries directly, you'll need an ugly work around with Craft 2 because you can't create such a condition via array by default, so you'll need to overwrite and extend more things  
  > **username_0**: I'm on Craft 2 for now. I ended up having to perform a ElementCriterialModel query and return  all entries in the section then in a foreach do a comparison with the two fields and return the ids that all matched to use in the entry source criteria. Not ideal but does the job.  
  > **username_2**: @username_0 Could you add the solution you ended up on as an official answer? Might end up helping someone in the future.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2018-09-02. Score: 1
  
  A workaround solution was to essentially do an criteria on the section, return all the records, use a conditional to find out which records have the same "parent ID" and ID", stores those in an array and then use the id criteria for the entry source.
  
  Something like:
  
  ```
  $criteria = craft()->elements->getCriteria(ElementType::Entry);
  $criteria->section = 'theSection';
  $criteria->limit = null;
  $articles = $criteria->find();
  
  // For storing matching entries on the conditional below
  $ids = [];
  
  foreach ($entries as $entry)
  {
       if($entry->fieldParentId == $entry->fieldId)
       {
           array_push($ids, $entry->id);
       }
  }
  
  ```
  
  This will then provide a list of ids that match the required criteria, which can then be used for a specific entry source.
  
  This has performance issues though, because you have to get the entire list of entries first each time.
  
  > **Comments:**
  > **username_1**: So why don't you query for entries with the same columns from the beginning and return only the ids? You can transform the criteria model into a query and include normal `where` conditions. Otherwise you might run into performance issues sooner or later  
  > **username_0**: @username_1 I'd agree that's a better way. We ended up changing the structure of the records, so we didn't have to do this in the end, but a query would be more performance friendly.  
  
  ---
  
  