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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Data Model Questions /

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

[SOLVED] How to get an array of pages ID?


Go to End


3 Posts   2088 Views

Avatar
Digital Punk

Community Member, 51 Posts

15 January 2010 at 5:26am

Edited: 15/01/2010 1:54pm

Hi there

I'm trying to get automatically an array of pages id (in ex. 29,38):

function GetCategoryNews() {
	  $holderid = DataObject::get("NewsHolder","ParentID = $this->ID");
          ...
	  $doSet = DataObject::get(
		$callerClass = "NewsPage",
		$filter = "`SiteTree`.ParentID IN (29,38)",
		$sort = "Date DESC",
		$join = "",
		$limit = ""
	  );
	  return $doSet ? $doSet : false;
	}

Maybe someone has an example how to get an array of pages ID or can help with this?

Best regards
Mindaugas

Avatar
Willr

Forum Moderator, 5523 Posts

15 January 2010 at 12:18pm

Sorry not sure I completely understand you here. The code you provided would get all the newspages which have the parents IDs of 29 or 38 that should work fine.

However your title suggests you want an array of all the Page ID's. For that you can use the map() method on any dataobjectset to return an array from a dataobjectset.

Avatar
Digital Punk

Community Member, 51 Posts

15 January 2010 at 1:53pm

No worries, I found solution - just made "holderid" as array:

$filter = "`SiteTree`.ParentID IN ($holderid)"

Anyway, thanks for the response!