Jump to content

Selector nested


Frank Vèssia
 Share

Recommended Posts

Hi, I need to select pages with a specific selector, going back to parent and find values inside two pagefields.
I can obtain pages with first pagefield like


$pages->find("parent.pagefield.name=value");

but I need to go deeper with
 


$pages->find("parent.pagefield.pagefield.id=value");

Any idea how to get this?

--------------------------------------------

Solved in this easy way:
 

$var = $pages->find("pagefield=value");
$pages->find("parent.pagefield=$var");

That's why I love PW :)

Edited by Sevarf2
Link to comment
Share on other sites

Hi,

Another way to do this is to use subselectors, which were introduced in Processwire 2.5.

The code would then be:

$pages->find("parent.id=[pagefield1.pagefield2.field=value]");

I love subselectors... :)

  • Like 5
Link to comment
Share on other sites

I would suggest reading this blog post, which lists all new stuff in Processwire 2.5. There are so many things, it's really impressive. I have actually bookmarked it due to all the really useful new functions.

The subselectors are in the section "Selectors", which doesn't appear in the top navigation, but comes just after "Sanitizer" and just before "Session".

Link to comment
Share on other sites

New additions arrived in April 2014 :-)

https://processwire.com/talk/topic/3768-processwire-dev-branch/?p=58722 (grouping)

https://processwire.com/talk/topic/3768-processwire-dev-branch/?p=64049 (or-groups and sub-selectors)

And are now documented here: http://processwire.com/api/selectors/ (but still missing grouping)

  • OR-groups: matching one group of selectors or another
  • Sub-selectors: selectors within selectors
Edited by kongondo
  • Like 1
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...