Peter Knight

Error with multiple page IDs in selector

5 posts in this topic

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.


 

 

Share this post


Link to post
Share on other sites

I think get() always returns a single page.

Have you tried

$pages->find("id=1|2|3");

which will return a PageArray.

3 people like this

Share this post


Link to post
Share on other sites
$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)

 

 

Share this post


Link to post
Share on other sites

$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). 

Share this post


Link to post
Share on other sites
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

 

 

1 person likes this

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.