Jump to content

Delete all children of a page


gerald
 Share

Recommended Posts

Almost one click - check out the Batch Child Editor module: http://modules.processwire.com/modules/batch-child-editor/ - either Edit or Replace mode.

You could also code an API snippet and store it in the Tracy Console panel snippets list - just run it from the parent page (either on the frontend, or while editing the parent page in the backend - the console will get $page as the page being edited):

image.thumb.png.9937f33df35ae1902a81f60b1223a92b.png

Or you could use that code in an AdminActions (http://modules.processwire.com/modules/process-admin-actions/) action.

 

  • Like 8
  • Thanks 1
Link to comment
Share on other sites

Hi gerald, another Austrian here :)

Adrian's modules are such great timesavers, indeed. But be careful using $pages->delete() as this is irreversible! You can also use $pages->trash() to have one extra step and then click on "empty trash" if you are sure everything is fine.

  • Like 2
Link to comment
Share on other sites

1 minute ago, bernhard said:

You can also use $pages->trash() to have one extra step and then click on "empty trash" if you are sure everything is fine.

On that important point, if you decide to use the BCE module, note this config setting:

image.png.90005d75b50dbd3dada238ba2659d523.png

  • Like 1
Link to comment
Share on other sites

1 hour ago, adrian said:

You could also code an API snippet and store it in the Tracy Console panel snippets list - just run it from the parent page (either on the frontend, or while editing the parent page in the backend - the console will get $page as the page being edited):

This may seem like a dumb question, but running this in the Tracy console actually deletes the pages on the site? Here's me, trashing -> going to trash, checking them all, confirming deletion like a sucker!

Link to comment
Share on other sites

1 hour ago, SamC said:

This may seem like a dumb question, but running this in the Tracy console actually deletes the pages on the site? Here's me, trashing -> going to trash, checking them all, confirming deletion like a sucker!

I am not sure I quite understand the question :) Anything you run in the Console panel will do whatever it is meant to do, so if you run that bit of API code, the pages will be deleted. As for the trash - there isn't any real need to empty that though. I do myself at times because I like things clean, but there isn't any actual need to.

  • Like 2
Link to comment
Share on other sites

15 minutes ago, adrian said:

Anything you run in the Console panel will do whatever it is meant to do, so if you run that bit of API code, the pages will be deleted.

Yep, that answers it thanks :) for some reason, I thought running code in tracy was like what "would" happen rather than being the equivalent of running the code in a template file. I think they refer to it as a brain fart... 

15 minutes ago, adrian said:

As for the trash - there isn't any real need to empty that though. I do myself at times because I like things clean, but there isn't any actual need to.

Same reason for me.

Link to comment
Share on other sites

1 hour ago, SamC said:

running code in tracy was like what "would" happen

I actually think it would be a great addition to have a "test" option in the Console panel - something that reported the changes that will happen - trouble is I think it would be a huge amount of work to implement.

  • Like 2
Link to comment
Share on other sites

  • 2 years later...

I was googling this and came across this. Here's the solution I came up with if it helps anyone. The module above crashed for me so I wrote my own. If you have a lot of pages it may not work as well, but after a few seconds it deleted 1700 pages for me under a specific template. Just run this on a processwire page:

Here's my solution (use at your own risk :) :

$page = $pages->get(1019)->children();
foreach ($page as $child) {
    $child->delete();
}

//1019 was the ID of a master template page that had all the children.

 

Hope this helps!

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

×
×
  • Create New...