Jump to content

X is not supported by FieldtypeImage in selector


MSP01
 Share

Recommended Posts

Hi,
I added some custom fields into image using the process descriped here:
https://processwire.com/blog/posts/pw-3.0.142/
 

Now I need to search for pages that have images with certain fields/content in them. But I'm running into a problem. Is it possible to use those fields in a selector?

It seems you cannot just go with $pages->find('images.somefield=something') because it throws an error. While I was using the included tag function in image fields using ('images.tags!=') worked but after replacing it with page reference field for better tagging, I cannot get it to function - nor any other field it seems.

 

Link to comment
Share on other sites

Searching for values of page reference fields assigned to images is unfortunately not fully supported (yet?). All custom fields for an image are stored in the database as a single JSON string, so things get a bit tricky there and the regular subfield logic of PW doesn't work.

What does work is searching for numeric page ids or full page paths. $pages->find('images.tagpage=1098') should work, as should $pages->find('images.tagpage=/tags/funny/'). $pages->find('images.tagpage.title%=tagtitle') won't work.

  • Like 2
Link to comment
Share on other sites

4 hours ago, BitPoet said:

What does work is searching for numeric page ids or full page paths.

The page name also seems to work: $pages->find('images.tags=the-page-name')

And in case it's not obvious, you can also find the page(s) used in the Page Reference field in a separate step and then use that Page/PageArray in the selector because it will be converted to ID(s) when treated as a string.

// Find the tags you want to search for
$search_tags = $pages->find("template=tag, title=blue|green");
// Find the pages with these tags in the images field
$results = $pages->find("images.tags=$search_tags");

 

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...