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?


1 Answer 1


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!

  • Great! Glad my blind guessing worked... Jul 21, 2014 at 10:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.