Jump to content

Selectors and PageArray field


BartekG
 Share

Recommended Posts

Let's say I've got a template with a field of a Page type. This field is set to handle multiple options (PageArray).

Now, I want to select all pages using this template, that have specific page set in the PageArray field.

Basically, something like this:

$pages->find('template=x pagearrayfield.contains=page1')

Is this possible? Any hints?

Thanks in advance.

Link to comment
Share on other sites

$pages->find("template=x, pagearrayfield=$somepage");

Where $somepage might be a page or a or multiples ID's . If $somepage is a page object, it will converted to a string with it's ID so you don't have to write $somepage->id but you could.

$pages->find("template=x, pagearrayfield=1230");
$pages->find("template=x, pagearrayfield=1230|1233|1203");
  • Like 3
Link to comment
Share on other sites

Thanks a lot. I actually tried to do it this way but kept getting errors that arrays can not be converted to strings, etc. Most probably I had made some silly mistake somehwhere, now I can't reproduce it. It works flawlessly. 

To make this thread a bit more useful for others I'll share the "discovery" I've made while tinkering with selectors and pageArray fields: the requests could be nested, like that:

$pages->find('template=x, pagearrayfield.pagearrayfieldNested.name=somethingsomething');

Probably a bit overhead for the database, but great feature nonetheless.

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

×
×
  • Create New...