Jump to content

Remove pages from field type page


jan
 Share

Recommended Posts

Hi there,

I have a template with a field type page. Now I try to remove one of the pages inside this field.

I think I'm kind of blind – it won't do what I want it do :rolleyes:

foreach ($myPage->pageField as $pageInField) {
    if( /* condition to find page to remove */ ) {
        $myPage->pageField->remove($pageInField);
        break;     
    }
}

Thank you!!!

Link to comment
Share on other sites

Something like this could probably work....

$x = $pages->get(1412);//necessarily verbose - could have done this in foreach
foreach ($x->myPageField as $f) {

   if ($f->name == 'example') {//set your condition
         $x->of(false);
         $x->myPageField->remove($f);
         $x->save();
   }
}
  • Like 2
Link to comment
Share on other sites

  • 8 months later...

I have a PageField that holds a single page.  I've been trying to find the proper way to unset it, I've seen an example of using "unset" but that doesn't feel right, or very processwire-ish.

Right now, I'm using

$facility->region_page = new NullPage();

But this also, just doesn't feel right but appears to work.

Is there a best practice for unsetting a pagefield?

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