Peter Knight Posted June 17, 2017 Posted June 17, 2017 is it possible to call multiple page IDs in a selector? I was trying to fetch a few specific pages by ID for a menu as follows $formnav = $pages->get("1216,1217,1218"); // Get specific pages echo $sideMenuForms->render($options, null, $formnav); and it throws the following error Fatal error: Exception: Unknown Selector operator: '' -- was your selector value properly escaped? field='1216', value='', selector: '1216,1217,1218' (in /var/www/vhosts/ It works if there is a single page ID specified but not multiples. Looking up the API reference, there is a "get by ID method" for multiple page IDs but it does nothing and no error $formnav = $pages->getById([1216,1217,1218]); // Get specific pages echo $sideMenuForms->render($options, null, $formnav); I can always revert back to a template or path based selector but was hoping to keep it based on ID for the moment.
alxndre Posted June 17, 2017 Posted June 17, 2017 I think get() always returns a single page. Have you tried $pages->find("id=1|2|3"); which will return a PageArray. 4
kixe Posted June 18, 2017 Posted June 18, 2017 $pages->get("id=1216|1217|1218"); // returns a single page (first match) $pages->getById([1216,1217,1218]) // returns a PageArray and is similar to $pages->find("id=1216|1217|1218"); It should work if $sideMenuForms->render() function expects a PageArray as third argument and if the PageArray is not empty (check with $formnav->count)
LostKobrakai Posted June 18, 2017 Posted June 18, 2017 $pages->find() in general does take a selector, but as a convenience it does also check if the supplied selector is a single ID as integer (and seemingly as string as well).
Peter Knight Posted June 19, 2017 Author Posted June 19, 2017 23 hours ago, kixe said: $pages->get("id=1216|1217|1218"); // returns a single page (first match) $pages->getById([1216,1217,1218]) // returns a PageArray and is similar to $pages->find("id=1216|1217|1218"); Both $pages->find("id=1|2|3"); and $pages->getById([1216,1217,1218]) worked. My original $formnav = $pages->getById([1216,1217,1218]); // Get specific pages wasn't returning the correct pages because the menu options needed this removing 'show_root' => true, Thanks everyone 2
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