Sinmok Posted July 17, 2018 Share Posted July 17, 2018 Hi all, Been a while ? I'm trying to achieve two kinds of selectors. One to select pages based on a parents field value and one to select pages where all children match a condition. For example, I am hoping to do something like this: <? //I want pages of template type task where the PARENT page field "closed" = 0 $groups = $pages->find("template=task,parent-of-page.closed=0") ?> Finally, I would like to select pages where all children follow a condition <?php //I want pages of template type group where ALL of the pages children field called my_int_field = 0 $matches = $pages->find("template=group, children.my_int_field=0"); ?> Are these two scenarios currently possible without iterating over a simpler selector first? Thanks! Link to comment Share on other sites More sharing options...
ottogal Posted July 17, 2018 Share Posted July 17, 2018 Just guessing: The second scenario should be possible with $matches = $pages->find("template=group, children('my_int_field=0')"); And the first one (even more guessing) with $groups = $pages->find("template=task,parent().closed=0"); or $groups = $pages->find("template=task,parent()->closed=0"); Or, more likely: $groups = $pages->find("template=task,parent(closed=0)"); Not sure at all. (Couldn't test it by myself.) Link to comment Share on other sites More sharing options...
Sinmok Posted July 17, 2018 Author Share Posted July 17, 2018 21 minutes ago, ottogal said: Just guessing: The second scenario should be possible with $matches = $pages->find("template=group, children('my_int_field=0')"); I can't find any documentation on the children('') selector. Where did you see it? Link to comment Share on other sites More sharing options...
netcarver Posted July 17, 2018 Share Posted July 17, 2018 The main selectors document is here. There are a couple of examples of using 'children' in selectors, starting here. Sorry, I can't say I've used that in selectors before so all I can do is signpost at the moment. Link to comment Share on other sites More sharing options...
ottogal Posted July 17, 2018 Share Posted July 17, 2018 5 hours ago, Sinmok said: I can't find any documentation on the children('') selector. Where did you see it? In the API Reference: https://processwire.com/api/ref/page/children/ 1 Link to comment Share on other sites More sharing options...
ottogal Posted July 17, 2018 Share Posted July 17, 2018 (edited) 5 hours ago, netcarver said: The main selectors document is here. There are a couple of examples of using 'children' in selectors, starting here. Have a look also to the section on Sub-selectors in that doc. So this should do it: $matches = $pages->find("template=group, children=[my_int_field=0]"); And for the other case: $groups = $pages->find("template=task,parent=[closed=0]"); Edited July 17, 2018 by ottogal 7 Link to comment Share on other sites More sharing options...
Sinmok Posted July 18, 2018 Author Share Posted July 18, 2018 I had no idea you could reference parent and children in a selector! I'll give this a go, thanks. Link to comment Share on other sites More sharing options...
Sinmok Posted July 19, 2018 Author Share Posted July 19, 2018 On 7/17/2018 at 7:58 PM, ottogal said: Have a look also to the section on Sub-selectors in that doc. So this should do it: $matches = $pages->find("template=group, children=[my_int_field=0]"); And for the other case: $groups = $pages->find("template=task,parent=[closed=0]"); This does not work. The selector compiles but does not return any matches. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now