<p>Fields in craft that are not element is query by something called element criteria model.
In twig you do:</p>

<pre><code>{% set result = craft.entries({
       section: 'boxes'
       orderBy: 'dateCreated asc'
       year: year,
       quarter： quarter
}).all() %}
</code></pre>

<p>In php</p>

<pre><code> $query = [
        'year' =&gt; $year,
        'quarter' =&gt; $quarter,
    ];
 $seasonBoxesQueryObject = \craft\elements\Entry::find()
                 -&gt;section('boxes')
                 -&gt;orderBy('dateCreated asc');
 $seasonBoxesQueryObject-&gt;year = $query['year'];
 $seasonBoxesQueryObject-&gt;quarter = $query['quarter'];
 $seasonBoxes = $seasonBoxesQueryObject-&gt;all();
</code></pre>

CC BY-SA 4.0
2019-07-16T02:43:04.957Z
Thanks Parry! This code works great!
aaron.cimolini
CC BY-SA 4.0
2019-07-16T02:40:51.457Z
2019-07-16T02:40:51.457Z
Parry Huang
<p>So I have a Entry type that has two custom fields on it. Both fields are integer fields. I'd like to make a query in PHP that gets the entries by two custom fields, both of which are integer values. Here is my code so far:</p>

<pre><code>    $query = [
        'year' =&gt; $year,
        'quarter' =&gt; $quarter,
    ];
    $seasonBoxes = \craft\elements\Entry::find()
                 -&gt;section('boxes')
                 -&gt;search($query)
                 -&gt;orderBy('dateCreated asc')
                 -&gt;all();
</code></pre>

<p>Please note: $year is independent of the entry creation date so I can't use the date filters.</p>

<craft3><entries><custom-field>
Entries search query by 2 custom fields
# Entries search query by 2 custom fields

(Asked by: username_0 on 2019-07-15)

So I have a Entry type that has two custom fields on it. Both fields are integer fields. I'd like to make a query in PHP that gets the entries by two custom fields, both of which are integer values. Here is my code so far:
    $query = [
        'year' => $year,
        'quarter' => $quarter,
    ];
    $seasonBoxes = \craft\elements\Entry::find()
                 ->section('boxes')
                 ->search($query)
                 ->orderBy('dateCreated asc')
                 ->all();

Please note: $year is independent of the entry creation date so I can't use the date filters.

**Tags:** craft3, entries, custom-field

---

## 1 answers

### Answer by username_1 on 2019-07-16. Score: 2 | Accepted answer

Fields in craft that are not element is query by something called element criteria model.
In twig you do:
{% set result = craft.entries({
       section: 'boxes'
       orderBy: 'dateCreated asc'
       year: year,
       quarter： quarter
}).all() %}

In php
 $query = [
        'year' => $year,
        'quarter' => $quarter,
    ];
 $seasonBoxesQueryObject = \craft\elements\Entry::find()
                 ->section('boxes')
                 ->orderBy('dateCreated asc');
 $seasonBoxesQueryObject->year = $query['year'];
 $seasonBoxesQueryObject->quarter = $query['quarter'];
 $seasonBoxes = $seasonBoxesQueryObject->all();

> **Comments:**
> **username_0**: Thanks Parry! This code works great!  

---

