thomas.isberg Posted November 30, 2012 Share Posted November 30, 2012 Hi! What's the best way to exclude pages with an unpublished or hidden parent anywhere in the hierarchy? In a find() that is. Thanks! .Thomas Link to comment Share on other sites More sharing options...
Soma Posted November 30, 2012 Share Posted November 30, 2012 The only way I see to do this in a find with a selector, is to do something like this: $up_pages = $pages->find("status=unpublished"); $sel = ''; foreach($up_pages as $p){ $sel .= ",has_parent!=$p->id"; } $pa = $pages->find("template=basic-page$sel"); foreach($pa as $p){ echo "<p>page: $p->title $p->url</p>"; } 3 Link to comment Share on other sites More sharing options...
diogo Posted November 30, 2012 Share Posted November 30, 2012 Maybe it would be a good idea to create a new method to find pages Starting in the homepage and running the branches from there, would this be possible? Like this we could do this kind of filtering very easily. Link to comment Share on other sites More sharing options...
thomas.isberg Posted November 30, 2012 Author Share Posted November 30, 2012 Thanks Soma! Does that actually work? I knew that array value was unsupported by has_parent, but didn't think about the possibility to put several has_parent conditions in there. I'll try that. Thanks, .Thomas Link to comment Share on other sites More sharing options...
ryan Posted December 2, 2012 Share Posted December 2, 2012 The simplest way would be just to post-filter them after your search. Meaning, whatever code you have outputting the found pages would just check the status and skip over any that had unpublished parents. foreach($items as $item) { $skip = false; foreach($item->parents as $parent) if($parent->is(Page::statusUnpublished)) $skip = true; if($skip) continue; // otherwise item is good to output echo "<li>$item->title</li>"; } But if you are also working with pagination, then you kind of need to have these things filtered ahead of time. In that case, I think Soma's method would be good. The hope is that you don't have too many unpublished pages to be found, that could slow the query. One way to further optimize that would be to find only unpublished pages that have children. $up_pages = $pages->find("status=unpublished, numChildren>0"); Link to comment Share on other sites More sharing options...
thomas.isberg Posted December 4, 2012 Author Share Posted December 4, 2012 Thanks Ryan, yes I needed the pagination. 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