1063Selector Magic in ProcessWire
ProcessWire's way of selecting ("getting") child pages is usually like this:
Get all children
$events = $page->children();
This can be fine-tuned with the Selector string.
Get all children, where the date or end_date is later than today, sort the results by date.
$events = $page->children("date|end_date>today,sort=date");
This works great, by we recently had a case, where a schedule talk had to be postponed to an unknown date in the future. I left the date field in the Backend empty, we need to modify the selection string:
Get all children, where the date or end_date is later than today OR where date is empty, sort the results by date.
$events = $page->children("(date|end_date >today), (date=), sort=date");
It's beautiful, that it's just a small change in the selection string:
- The additional parenthesis
()around(date|end_date >today)and(date=)specify an OR relation. Default is AND, here it means: select children with either(date|end_date >today)OR(date=)- no date. date=means that the date field is empty
Resources
- More about Selectors: https://processwire.com/docs/selectors/
- Seleceting an Empty Field: https://processwire.com/talk/topic/957-how-to-find-elements-with-empty-field/