Snippets - Little bits of code to make you happy
Getting objects from multiple child pagesTweet
14 April 2009 | | | Supports v2.4, v2.3
When you want to create a DataObjectSet encompasing objects from all the current pages children you can do something like this
$pageIDs = $this->getDescendantIDList(); $ObjectSet = DataObject::get( "Object", "`ObjectPageID` IN (" . implode(",", $pageIDs) . ")" );
The first line creates an array of the ID's from all, with the current page and any descendant page ID's.
The second line onwards then gets all Objects that have an ObjectPageID that is either the current page's ID, or any child page of the current page.
You can then add the usual filter, join or limit clauses to the DataObject::get call.