Jump to content

has_parent issue


Frank Vèssia
 Share

Recommended Posts

I have this selector

$photos = $pages->find("template=picture,has_parent=2293|1038,limit=20,sort=-created");

I got this warning even i can show correctly my photos...

Warning: preg_match() expects parameter 2 to be string, array given in /public_html/wire/core/Sanitizer.php on line 266/
  • Like 1
Link to comment
Share on other sites

like this?

$parents = array(2293,1038);
$photos = new PageArray();
foreach($parents as $parent) $photos->add($pages->find("template=picture,has_parent=$parent,limit=20,sort=-created"));
$photos = $photos->sort("-created")->slice(0,20);
Link to comment
Share on other sites

has_parent only works with 1 page because the only reason it exists is to provide the Page::find() capability -- or at least, that was the original intention.

I'm not sure what the structure you have is exactly, but you can use "|" with parent. So if you could narrow it down to the parents, then you could do it. Something like this might provide an equivalent functionality, though not ideal if the potential number of parents is huge.

$parents = new PageArray();
$hasParents = $pages->find("id=2293|1038"); 
foreach($hasParents as $hasParent) {
 $parents->add($hasParent->find("num_children>0, template!=picture")); 
}

$selector = "template=picture, sort=-created, limit=20, parent=";
foreach($parents as $parent) $selector .= $parent->id . "|";
$photos = $pages->find(rtrim($selector, '|')); 
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...