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

CC BY-SA 4.0
2021-10-04T14:46:00.420Z
2021-10-04T14:46:00.420Z
MoritzLost
<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>

CC BY-SA 4.0
2021-10-04T17:55:43.120Z
2021-10-11T09:50:13.743Z
2021-10-11T09:50:13.743Z
lassemt
<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>

<query><element>
Pass parameters to element query as array - in PHP
# 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() 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() returns an EntryQuery). You can chain additional methods to the query afterwards:
use craft\elements\Entry;

$query = Entry::find()->id(11)->relatedTo(22);
$results = $query->all();

See Element Queries and 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:
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
Yii's configure method


---

