Snippets - Little bits of code to make you happy
Getting objects from multiple child pages
Tweet14 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.
1 Comments
RSS feed for comments on this page RSS feed for all comments
James Barnsley
16/07/2012 2:29am (10 months ago)
Hi Hamish,
Super-handy to know this tidy snippet. Have you had problems loading multiple filters for the one GET? Ie:
$ObjectSet = DataObject::get(
'Object',
'ShowPage = 1 AND (ObjectPageID = 1 OR ObjectPageID = 2)'
);
I haven't managed to get this syntax working properly and am wondering if it is at all possible.
Post a comment ...
You cannot post comments until you have logged in. Login Here.