Jump to content

Recommended Posts

Posted

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!

Posted

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

Posted
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?

Posted

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.

Posted (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 by ottogal
  • Like 7
Posted

I had no idea you could reference parent and children in a selector! I'll give this a go, thanks.

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

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...