Jump to content

Parent field selector and children all selector


Sinmok
 Share

Recommended Posts

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

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

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

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 by ottogal
  • Like 6
Link to comment
Share on other sites

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

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