Answers.Body: <p>The <a href="https://docs.craftcms.com/api/v3/craft-base-element.html#method-find" rel="nofollow noreferrer"><code>Element::find()</code></a> method does not take any parameters, it just serves as the factory method for the appropriate element query for the given element type (for example, <a href="https://docs.craftcms.com/api/v3/craft-elements-entry.html#method-find" rel="nofollow noreferrer"><code>Entry::find()</code></a> returns an <a href="https://docs.craftcms.com/api/v3/craft-elements-db-entryquery.html" rel="nofollow noreferrer">EntryQuery</a>). You can chain additional methods to the query afterwards:</p>
  <pre class="lang-php prettyprint-override"><code>use craft\elements\Entry;
  
  $query = Entry::find()-&gt;id(11)-&gt;relatedTo(22);
  $results = $query-&gt;all();
  </code></pre>
  <p>See <a href="https://craftcms.com/docs/3.x/element-queries.html" rel="nofollow noreferrer">Element Queries</a> and <a href="https://craftcms.com/docs/3.x/entries.html#querying-entries" rel="nofollow noreferrer">Querying Entries</a> for reference.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-10-04T14:46:00.420Z
Answers.LastActivityDate: 2021-10-04T14:46:00.420Z
Answers.UserDisplayName: MoritzLost
Answers.Body: <p>This is because it's a twig feature in Craft. If I remember correctly it's done in the CraftVariable and look something like this under the hood:</p>
  <pre class="lang-php prettyprint-override"><code>use Craft;
  use craft\elements\Entry;
  
  $query = Entry::find();
  Craft::configure($query, $criteria);
  return $query;
  </code></pre>
  <p>Where the <code>$criteria</code> is the &quot;query config&quot;.</p>
  <p><strong>Edit:</strong>
  Some references for you.</p>
  <ul>
  <li><a href="https://github.com/craftcms/cms/blob/86dcff6444f0bda0ca56af2fd83d4e4cbcddeeb6/src/web/twig/variables/CraftVariable.php#L240" rel="nofollow noreferrer">Craft Variable soruce code</a></li>
  <li><a href="https://www.yiiframework.com/doc/api/2.0/yii-baseyii#configure()-detail" rel="nofollow noreferrer">Yii's configure method</a></li>
  </ul>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-10-04T17:55:43.120Z
Answers.LastActivityDate: 2021-10-11T09:50:13.743Z
Answers.LastEditDate: 2021-10-11T09:50:13.743Z
Answers.UserDisplayName: lassemt
Body: <p>In Twig, we can do this like this:</p>
  <pre><code>craft.entries({
      id: 11,
      relatedTo: 22,
  })
  </code></pre>
  <p>But in PHP code, this does not work:</p>
  <pre><code>\craft\elements\Entry::find(
              [
                  'id' =&gt; 11,
                  'relatedTo' =&gt; 22,
              ],
          )
  </code></pre>
  <p>I think that only way would be loop through array and apply to initial query object each array position as element query method. Or maybe am I wrong?</p>
  <p>I checked Craft source code and in file <code>base/Element.php</code>, in method <code>find()</code> there is no param to pass array of element query methods into.</p>
  
Tags: <query><element>
Title: Pass parameters to element query as array - in PHP
ThreadText: # Pass parameters to element query as array - in PHP
  
  (Asked by: username_0 on 2021-10-04)
  
  In Twig, we can do this like this:
  
  ```
  craft.entries({
      id: 11,
      relatedTo: 22,
  })
  
  ```
  
  But in PHP code, this does not work:
  
  ```
  \craft\elements\Entry::find(
              [
                  'id' => 11,
                  'relatedTo' => 22,
              ],
          )
  
  ```
  
  I think that only way would be loop through array and apply to initial query object each array position as element query method. Or maybe am I wrong?
  
  I checked Craft source code and in file `base/Element.php`, in method `find()` there is no param to pass array of element query methods into.
  
  **Tags:** query, element
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2021-10-04. Score: 2
  
  The [`Element::find()`](https://docs.craftcms.com/api/v3/craft-base-element.html#method-find) method does not take any parameters, it just serves as the factory method for the appropriate element query for the given element type (for example, [`Entry::find()`](https://docs.craftcms.com/api/v3/craft-elements-entry.html#method-find) returns an [EntryQuery](https://docs.craftcms.com/api/v3/craft-elements-db-entryquery.html)). You can chain additional methods to the query afterwards:
  
  ```php
  use craft\elements\Entry;
  
  $query = Entry::find()->id(11)->relatedTo(22);
  $results = $query->all();
  
  ```
  
  See [Element Queries](https://craftcms.com/docs/3.x/element-queries.html) and [Querying Entries](https://craftcms.com/docs/3.x/entries.html#querying-entries) for reference.
  
  
  ---
  
  ### Answer by username_2 on 2021-10-04. Score: 2
  
  This is because it's a twig feature in Craft. If I remember correctly it's done in the CraftVariable and look something like this under the hood:
  
  ```php
  use Craft;
  use craft\elements\Entry;
  
  $query = Entry::find();
  Craft::configure($query, $criteria);
  return $query;
  
  ```
  
  Where the `$criteria` is the "query config".
  
  **Edit:**
  Some references for you.
  
  * [Craft Variable soruce code](https://github.com/craftcms/cms/blob/86dcff6444f0bda0ca56af2fd83d4e4cbcddeeb6/src/web/twig/variables/CraftVariable.php#L240)
  * [Yii's configure method](https://www.yiiframework.com/doc/api/2.0/yii-baseyii#configure()-detail)
  
  
  ---
  
  