Jump to content
gerald

Delete all children of a page

Recommended Posts

Hi all,

I use version 3.0.62. Is there a way to delete all children of a page with one click - without parent page?

thanks

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
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!

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

One more option, but requires a pro module. Lister Pro has a delete/trash action in its set of bundled actions. I use this one a lot.

2018-01-30_095247.png.aac9e3a6489f3f7f41e2b3100738903f.png

  • Like 4

Share this post


Link to post
Share on other sites

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!

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.

  • Similar Content

    • By louisstephens
      So I went to revisit a project that I put on hold and was met with the following error when trying to trash a page "Operator '&' is not supported for 'status' in ../wire/core/PageFinder.php: 2211
      else if(!$database->isOperator($operator)) { throw new PageFinderSyntaxException("Operator '$operator' is not supported for '$field'."); } I have searched through my templates just to make sure I didn't do anything screwy, but I have no clue why this error is being generated. I can individually delete an item from the trash, but I cant empty the entire trash. 
    • By EyeDentify
      Hello Dear PW Gurus.

      Hope you fair well in these Corona Crisis times.

      Anyhow, i have a problem with a Cryptic error message that shows up when i am trying to Delete images out of a Images field.
      The Error message does say a little but it does not make sense to me why i can´t delete the images because of it.

      Is it some permission issue perhaps?

      I will attach screenshots of it and what i did prior to it.
      I am from sweden so ignore the funny words here and there.

      Hope you all can send me on the right track.
      i am running PW 3.0.139 on this install.

      Step1:

      Step 2: Select the images with the trashcan symbol

       
      Step 3: Cryptic Error message

      I am scratching my head on this one, have not seen this before.

      Thankfull for all help.
      /EyeDentify
    • By louisstephens
      So I reread my first draft, and it made absolutely no sense (I deleted it to hopefully better explain myself).  I am trying to make a system (that to me is a bit complicated) utilizing jquery and processwire together. My whole goal is to put a url like https://domain.com/launch?first_name=jim&occupation=builder in a script tag on another site(just a localhost .php page) to then pull out the data for that person and append to divs etc. Basically, the initial script tag would point to "launch" which has a content-type of "application/javascript". Using jquery, I would pull out the persons name and occupation and then make a specific ajax get request to "domain.com/api" (in json format) for a look up of the person. Essentially then I could pull that particular person's information from the json data, and do with it how I please in the "launch" page.  In processwire, I have a page structure like:
      People -Jim Bob (template: person ) --Occupations (template: basic-page) ---Builder (template: occupation) ---Greeter (template: occupation) It is really just a bunch of people with their occupations and a few fields to the occupation template. With the "api" (template: api) url, I was hoping to return all the data (of people) in json format like:
      Example Format:
      { "id": 1, "title": "Jim Bob", "occupations": { "builder": { "id": 44, "title": "Builder", "years_worked": 1, "etc": "ect", }, "Greeter": { "id": 44, "title": "Greeter", "years_worked": 1, "etc": "ect", }, } } Where I get lost is really outputting the page names and nesting in the occupations into json. I have used Pages2JSON before, but I was a bit lost on how to implement what i was thinking.
       
      I have access to all the local host files, but I was hoping to kind of build out a "system" where I could place the script tag/parameters in any project, and be able to interact with the data without doing an ajax call on the actual site. In a way, this would keep processwire handling all the data and requests, and my other "projects" just with a simple script tag. This might all be way too much/over complicated, but I couldn't quite wrap my head around how to achieve it. 
    • By Piguanet
      Hola, soy bastante nueva en esto. Tengo en la papelera de mi CMS 4300 aprox. archivos que no puedo borrar. Cuando le doy la opción vaciar me dice que no se puede y continuan ahi.

       
    • By kaba86
      Hello PW Community, really glad that discovered this CMS recently, it is very strange it took so long That idea of no front design limitations is just awesome!
      Need to say that I have a bit of knowledge of html and css, but almost no php, so I need your help.
      What I want to do is an article posting  cms, with this structure:
       
      - Homepage - Projects - Articles -- Category 1 --- Articles of category 1 -- Category 2 --- Articles of category 2 - About - Contact Found this ProcessWire Profile https://github.com/tutsplus/how-to-create-an-ajax-driven-theme-for-processwire
      It covers almost all my needs, except the menu. When I add a childpage for this page http://artist.nicegrp.com/publications/world-world/ , World:World doesn't appear under Writings & Publications.
      I need a menu that works like a breadcrumb, that shows on the menu the category that you are viewing. So when I'm in articles page, on the menu it shows only articles and it's categories. When I get into a category, that category takes state active link but doesn't show on the menu links and titles for contained articles. How can I do that?
      Sorry for my long writing and English, it is not my native but I hope you understood what I need. Can you help me with that?
      Thank you
       
×
×
  • Create New...