Jump to content

PageField custom PHP code to find selectable pages


a-ok
 Share

Recommended Posts

Hi folks,

I am using the PageField to find selectable pages and I'm using the 'custom PHP code' field to find my pages.

However, the following isn't bringing back any pages:

$pages->find('parent=/tags/' . $page->parent->name . '/');

I have tested this code on the page template, and it returns the correct pages but entering this into the custom PHP field returns an empty dropdown field.

Any thoughts?

Link to comment
Share on other sites

Hi folks,

I am using the PageField to find selectable pages and I'm using the 'custom PHP code' field to find my pages.

However, the following isn't bringing back any pages:

$pages->find('parent=/tags/' . $page->parent->name . '/');

I have tested this code on the page template, and it returns the correct pages but entering this into the custom PHP field returns an empty dropdown field.

Any thoughts?

Did you try to write "return " ahead of the above command like this:

return $pages->find('parent=/tags/' . $page->parent->name . '/');

?

  • Like 2
Link to comment
Share on other sites

You have to use return as basically you can do more complex PHP over multiple lines using that option, so you can do a selector to get a certain bit of info to use in another selector for example and really do some interesting stuff there (sorry that might sound vague but examples are eluding me at present - I just know that's how I've used it in the past).

Link to comment
Share on other sites

You could for example have an user selection, where already chosen users in other pages are excluded. But do this only if the page is the right template as otherwise it'll break the lister selection of the field. So it can get quite complex in this field.

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...