Jump to content

Find pages with grand children older than x days, but not newer than x days


Recommended Posts

Posted

I was trying to get pages that have grand children older than 14 days, but not newer than 14 days.

$cities = wire('pages')->find('template=city, !children.children.created>"14 days ago"');

$cities = wire('pages')->find('template=city, children.children.created<"14 days ago"')->not('template=city, children.children.created>"14 days ago"');

$cities = wire('pages')->find('template=city, children.children.created<"14 days ago"')->remove('template=city, children.children.created>"14 days ago"');

The first one is, I guess, not supported by PW (not to mention something like created!>time), but the last two should work in my option. The filter() doesn't work either here.

Please note, that all city pages have grand children older than 14 days, so I can't just find('template=cities, children.children.created<"14 days ago"') because that includes those pages having grand children from yesterday for example.

Posted
8 hours ago, suntrop said:

but the last two should work in my option. The filter() doesn't work either here.

Times as strings are not supported for in-memory selectors, only PageFinder (database) selectors. You'll need to use timestamps (e.g. via strtotime).

Posted

Hadn't luck with timestamp either. Changed it now to this, and it's working for me. Anyway, thanks for your answer!

$remove = wire('pages')->find('template=city, children.children.created>"14 days ago"');
$cities = wire('pages')->find('template=city, children.children.created<"14 days ago"')->removeItems($remove);

 

Posted

Did you try:

$cities = wire('pages')->find('template=city, children.children.created<"14 days ago", !children.children.created>"14 days ago"')

Without the @ syntax the two selectors for children should work if they match on different children.

Posted
1 hour ago, LostKobrakai said:

 


$cities = wire('pages')->find('template=city, children.children.created<"14 days ago", !children.children.created>"14 days ago"')

 

This one has a strange outcome. For example …

find('template=city, children.children.created<"14 days ago"');

Result:

  • Hamburg
  • Berlin
  • Hannover
  • Wiesbaden

 

find('template=city, children.children.created>"14 days ago"');

Result:

  • Hamburg
  • Bremen

 

find('template=city, children.children.created<"14 days ago", !children.children.created>"14 days ago"');

Result:

  • Hamburg

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