valan Posted March 4, 2016 Share Posted March 4, 2016 Is it possible to search pages by selector and get array (or separated string) of page ids instead of populated Pages in PageArray? I have several thousands of pages in return and want to avoid memory limit/performance issues. All I need are page ids. Link to comment Share on other sites More sharing options...
diogo Posted March 4, 2016 Share Posted March 4, 2016 Not knowing exactly what you want to do it's difficult to help, but it seems to me that it would be better to use "limit" on the selector and do whatever you have to do in chunks. Honestly I don't see how an array of 10000 IDs could be useful. Link to comment Share on other sites More sharing options...
LostKobrakai Posted March 4, 2016 Share Posted March 4, 2016 $pages->find($selector, array('returnVerbose' => false, 'loadPages' => false)); 4 Link to comment Share on other sites More sharing options...
valan Posted March 4, 2016 Author Share Posted March 4, 2016 @LostKobrakai - thanks! I know loadPages, but returnVerbose is smth new... haven't seen any documentation on it. Does it work in PW2.7? Will check myself.Thanks! Link to comment Share on other sites More sharing options...
adrian Posted March 4, 2016 Share Posted March 4, 2016 A "getIds" option might be nice. $pages->find($selector, array('getIds' => true)); It would be in a similar vane to: $pages->getByPath('/path/to/page', array('getID' => true)); but would obviously return an array of IDs, rather than a single one like with getByPath. Or maybe: $pages->getIds($selector); which has the same feel as: $pages->count($selector); 2 Link to comment Share on other sites More sharing options...
LostKobrakai Posted March 4, 2016 Share Posted March 4, 2016 The returnVerbose is something I found in the PageFinder class. Not sure how much it's needed. 1 Link to comment Share on other sites More sharing options...
valan Posted March 4, 2016 Author Share Posted March 4, 2016 3 years PWired, but PW still surprises. Right marriage. 5 Link to comment Share on other sites More sharing options...
gRegor Posted March 4, 2016 Share Posted March 4, 2016 PageFinder has a findIDs() method that sets the returnVerbose attribute. It doesn't set loadPages attribute, but I presume when returnVerbose is off it automatically does not return pages. Untested, but this should work: (Oops. Doesn't work. See below.) $pages->findIDs($selector); 1 Link to comment Share on other sites More sharing options...
adrian Posted March 4, 2016 Share Posted March 4, 2016 PageFinder has a findIDs() method that sets the returnVerbose attribute. It doesn't set loadPages attribute, but I presume when returnVerbose is off it automatically does not return pages. Untested, but this should work: $pages->findIDs($selector); I thought I remembered there being something like that, but couldn't find it. Thanks for the reminder! PS And of course findIDs makes much more sense than my suggest getIds Link to comment Share on other sites More sharing options...
LostKobrakai Posted March 4, 2016 Share Posted March 4, 2016 That's not going to work like that. First of all $pages is not pageFinder, $pages->pageFinder() is. Also the first argument is typehinted to Selectors, so putting a string won't work as well. That's why I've not mentioned it as I find it more confusing to use instead of the simple "add those options". If there would be a companion function in the Pages class it would be nice. $pages->pageFinder()->findIDs(new Selectors($selector)); 1 Link to comment Share on other sites More sharing options...
gRegor Posted March 4, 2016 Share Posted March 4, 2016 Ah, did not realize that. Good to know. A shortcut findIDs() method in Pages.php seems like a good idea to add. Link to comment Share on other sites More sharing options...
Frank Unkelbach Posted June 7, 2017 Share Posted June 7, 2017 Just a quick note if you didn't know how to get an array of page id's from a page array: $array = $pageArray->explode('id'); Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now