Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Get DataObejctSet of pages with ID filter

Go to End

4 Posts   1808 Views


Community Member, 20 Posts

5 September 2009 at 9:35am

Hello Experts,

I need help! :-) I want a DataObejctSet consisting of a specific type of pages, filtered by their id.
In other words, i want the query to return 3 pages, all of the type "WithPreviewPage", identified by their id.

The pages are of the type "WithPreviewPage" and are not necessarily children of the same page.

The below code will give me all of the pages of type "WithPreviewPage", but i don't know how to filter by ID's.
I can do DataObject::get("WithPreviewPage", "Sort = 3"); which will give me the record with the sort order 3, but as soon as i attempt to use ID i get an "Website error", no further description.

class ForsidePage_Controller extends Page_Controller {
function showPreviews() {
$records = DataObject::get("WithPreviewPage");//, $filter, $sort, $join, $limit);
print "<pre>";
print "</pre>";
return ($records);

Can anyone please show me how to return the 3 pages of WithPreviewPage with the id's 8,9,10.

Thank you for your time.


Forum Moderator, 5523 Posts

5 September 2009 at 11:25am

"Website error", no further description.

Put the site into dev mode so you can see the full error messages. Add Director::set_environment_type("dev"); to your _config file or add ?isDev=1 to the url.

Try quoting the Page Table Name as well.

DataObject::get("WithPreviewPage", "`WithPreviewPage`.ID IN ('8,9,10')");


Community Member, 545 Posts

5 September 2009 at 11:33am

Personally I'd just Add a showPreview field to the WithPreviewPage Object that way you could filter a lot easier

That way your query could look like

$records = DataObject:get("WithPreviewPage","showPreview=1");

plus you won't need to edit the code to look for specific IDs if you want to change it later. You just click a check box in the CMS.


Community Member, 20 Posts

10 September 2009 at 8:36am

Thx willr, adding the table name did the trick.

Zenmonkey, we did think of this, but we would rather select the pages to show on the homepage, and not on the individual pages.

Thank you for your answers.