<p>I have not tried this against a working database but based on something very similar this should work:</p>

<pre><code>{% set matchingPhotos = craft.assets.folderId(5).relatedTo({
  targetElement: craft.entries({
    slug : 'example-photographer',
    section : 'photographers'
  }),
  field : assetsPhotographerField
}) %}
</code></pre>

<p>In reverse what you are doing is getting all the photographer entries that match that slug that are related to the assets field in that specific folder id...does that make any sense?!</p>

<p>You may need to swap <code>targetElement</code> out for <code>sourceElement</code> - I never know which way round it should be!</p>

CC BY-SA 3.0
2014-07-21T10:28:14.627Z
Great! Glad my blind guessing worked...
Josh Angell
CC BY-SA 3.0
2014-07-18T10:37:52.680Z
2014-07-18T10:37:52.680Z
Josh Angell
<p>For a website I'm currently building I have a bunch of photos within an Assets folder (folder id of 5) that I have linked to "Photographer" entries within a "Photographers" structure.</p>

<p>I am now trying to search by the photographer slug in order to show photos for a specific photographer:</p>

<pre><code>{% set searchQuery = "photographer::example-photographer" %}
{% set matchingPhotos = craft.assets.folderId(5).search(searchQuery) %}
</code></pre>

<p>Unfortunately however the <code>matchingPhotos</code> data set is always empty, even though I'm very sure that a photographer exists with a slug of <code>example-photographer</code> and there are photos linked to this photographer in the assets folder..</p>

<p>Is the way I'm trying to search correct?</p>

<p>Thanks!</p>

<assets><search>
searching assets - using related entry slug
# searching assets - using related entry slug

(Asked by: username_0 on 2014-07-18)

For a website I'm currently building I have a bunch of photos within an Assets folder (folder id of 5) that I have linked to "Photographer" entries within a "Photographers" structure.
I am now trying to search by the photographer slug in order to show photos for a specific photographer:
{% set searchQuery = "photographer::example-photographer" %}
{% set matchingPhotos = craft.assets.folderId(5).search(searchQuery) %}

Unfortunately however the matchingPhotos data set is always empty, even though I'm very sure that a photographer exists with a slug of example-photographer and there are photos linked to this photographer in the assets folder..
Is the way I'm trying to search correct?
Thanks!

**Tags:** assets, search

---

## 1 answers

### Answer by username_1 on 2014-07-18. Score: 4 | Accepted answer

I have not tried this against a working database but based on something very similar this should work:
{% set matchingPhotos = craft.assets.folderId(5).relatedTo({
  targetElement: craft.entries({
    slug : 'example-photographer',
    section : 'photographers'
  }),
  field : assetsPhotographerField
}) %}

In reverse what you are doing is getting all the photographer entries that match that slug that are related to the assets field in that specific folder id...does that make any sense?!
You may need to swap targetElement out for sourceElement - I never know which way round it should be!

> **Comments:**
> **username_1**: Great! Glad my blind guessing worked...  

---

