<p>There is a <a href="https://docs.craftcms.com/v3/relations.html#the-relatedto-parameter" rel="nofollow noreferrer">related to</a> parameter you can use</p>



<pre><code>Entry::find()
  -&gt;section($section)
  -&gt;relatedTo(['targetElement' =&gt; $image-&gt;id, 'field' =&gt; 'galleryImages')
  -&gt;all();
</code></pre>

CC BY-SA 4.0
2018-08-29T06:03:04.713Z
2018-08-29T06:03:04.713Z
Robin Schambach
<p>I have some entries with a multi-select field called "gallery". We can choose many images to this field.</p>

<p>I have a given image, how can I query entries whose "gallery" contains this given image? Thx!</p>

<p>I have tried like this with no success:</p>

<pre><code>Entry::find()
  -&gt;section($section)
  -&gt;galleryImages('contains' . $image-&gt;id)
  -&gt;all();
</code></pre>

<plugin-development><custom-fieldtype><query><elementquery>
How to query entries by field values
# How to query entries by field values

(Asked by: username_0 on 2018-08-29)

I have some entries with a multi-select field called "gallery". We can choose many images to this field.
I have a given image, how can I query entries whose "gallery" contains this given image? Thx!
I have tried like this with no success:
Entry::find()
  ->section($section)
  ->galleryImages('contains' . $image->id)
  ->all();

**Tags:** plugin-development, custom-fieldtype, query, elementquery

---

## 1 answers

### Answer by username_1 on 2018-08-29. Score: 4 | Accepted answer

There is a related to parameter you can use
Entry::find()
  ->section($section)
  ->relatedTo(['targetElement' => $image->id, 'field' => 'galleryImages')
  ->all();


---

