renobird Posted March 24, 2012 Share Posted March 24, 2012 Hello All, Is there currently a native method or module that would allow me to make bulk edits? For example, I need to change the template that 2 dozen pages use — editing them one at a time is taking quite a bit of time. I haven't had to delete a lot of pages yet, but I can see where that could get tedious too. *I suppose I could just update the DB via SQL, but ideally I'd like to be able to stay in the admin. Link to comment Share on other sites More sharing options...
charliez Posted March 24, 2012 Share Posted March 24, 2012 +1 THat would be a good feature... Link to comment Share on other sites More sharing options...
Soma Posted March 25, 2012 Share Posted March 25, 2012 No there's no module yet, but was discussed and mentioned a couple times. I think there's a guy doing something concerning this, but no clue what and how good it will be. http://clintonskakun...rocesswiresexy/ I'm sure something could be done with my datatable module http://processwire.c.../704-datatable/ also provides some nice, not bulk, but faster editing workflow now with the latest "wiretab" stay on tab settings feature. I know there's easy approaches doing a module for this, that would make a custom admin page output markup table with pulldowns that lets you select template and save in a row. It surely something that will come in some form sooner or later. Remember you can do some really advanced cool stuff "very" easily with PW API and modules what ever type. I also always have a tool.php in the root when developing. And do some operations via API from there. Though not something everyone is to his likes. You could also add something like following in a template and load the page: $pa = $pages->find("parent=/portfolio/,template=basic-page"); foreach($pa as $p) $p->set("template","advanced-template")->save(); or in a php with bootstrap include("./index.php"); $pa = wire("pages")->find("parent=/portfolio/, template=basic-page"); foreach($pa as $p) $p->set("template","advanced-template")->save(); Edit: corrected and simplifed code example 1 Link to comment Share on other sites More sharing options...
diogo Posted March 25, 2012 Share Posted March 25, 2012 And to delete lots of pages: $pa = $pages->find("selector"); foreach($pa as $p) $p->delete(); 1 Link to comment Share on other sites More sharing options...
totoff Posted January 23, 2013 Share Posted January 23, 2013 (edited) hello forum, i would like to bulk add new (sub)pages via the api. how would you do that? and - sorry if this is a silly question, i'm still learning - i wonder where functions such as delete() or save() come from? are they part of the pw api and if so, are they documented somewhere? or are they native php functions? sorry again, i'm not a php professional at all ... thanks for your answers. EDIT: Found answers to part 2 of my question: save() and delete() are methods for the $page object. however, still stuck on how you would add new pages in a rush. Edited January 23, 2013 by totoff Link to comment Share on other sites More sharing options...
Soma Posted January 23, 2013 Share Posted January 23, 2013 The forum is full of example for it if you search for it enough Basic code needed to add new pages would be. $np = new Page(); // create new page object $np->template = "basic-page"; $np->parent = "/about/"; // or id or page object $np->title = "Hello World"; $np->save(); It's very easy once you get the hang of it. There's a lot more you can do and sometimes it can be handy to know it to import stuff and create pages via API or in modules. If you want to can take a look at my super duper page creation tool, which is a work in progress but you can add endless amount of pages while looking TV. http://processwire.com/talk/topic/2138-process-tools-create-pages-wip/ 1 Link to comment Share on other sites More sharing options...
totoff Posted January 23, 2013 Share Posted January 23, 2013 hi soma, thanks for your reply. in fact i did search the forum before posting and i found a lot of examples on how to add a single page via the api including your own example given in this thread. however, what i'm unsure about is how one would add more than one page in a rush. i found some information in the forum that seemed to be helpful and the import() method in the api, but still unsure how to do it. i'm sure one needs to create an array holding the necessary page information and than iterate over it with foreach... but how exactly? i already have a parent page and need to create about 50 subpages. if you could set me on the right track i would greatly appreciate. thanks for pointing me to your very helpful module. but for the sake of my learning curve i would love to find out how to do it via the api before i fall back to a module. Link to comment Share on other sites More sharing options...
nik Posted January 23, 2013 Share Posted January 23, 2013 Maybe something like this then, extending from Soma's example: $titles = array('first', 'second', 'third');foreach($titles as $title) { $np = new Page(); $np->parent = '/path/to/your/parent/page/'; $np->template = 'basic-page'; $np->title = $title; $np->save();} So there's no need for WireArray or PageArray here, nor import() - which has nothing to do with creating new pages but importing Page objects into a PageArray. And if you'd want to import some more data in there at once, take at look at this as well: http://modules.processwire.com/modules/import-pages-csv/ 5 Link to comment Share on other sites More sharing options...
totoff Posted January 23, 2013 Share Posted January 23, 2013 ahhrg, i was not seeing the wood for the trees ... so simple, my thinking was much to complicated. many thanks, nik! 1 Link to comment Share on other sites More sharing options...
alan Posted April 12, 2017 Share Posted April 12, 2017 (edited) Thanks @Soma, I just created an array in Sublime Text in 3mins and then used a for loop and a modified version your code to create 62 pages in a click, continually amazed by the simple power of PW. PS: This was my code, it's obvious/simple, but just in case there's someone looking for a simple example (caution, only call the function once as it just blasts new pages into creation function make_pages() { $out =''; $mypages = array("1st Degree", "2nd Degree", "3rd Degree", "Abdomen", "Allergic Reaction", "Anger And Indignation", "Animal Bites", "Back", "Bad Fish", "Bad Meat", "Beesting", "Blow To Eardrum", "Blow To Eyes", "Blow To Orbit", "Blow To Outer Ear", "Blow/whiplash", "Body Injury", "Breathway Constriction", "Bruises", "Burns", "Cold", "Crushed Fingers", "Dizziness and Vertigo", "Dog Bites", "Ear", "Emotional Upset", "Extremeities", "Eye", "Fainting/collapse", "Fall On Mouth/teeth", "Fear And Fright", "Food Poisoning", "Fractures", "Frostbite", "General", "Grief And Betrayl", "Head", "Heat", "Heatstroke", "Insect Bites", "Joint Sprain", "Mouth", "Muscular Strains", "Neck", "Nerve Injury", "Nose", "Nosebleed", "Overeating", "Overuse Of Alcohol, Drugs, Tabaco, Food", "Physical Injury", "Poison Ivy", "Puncture Wounds", "Rich Food", "Shock And Loss Of Love", "Skin Rash, Swells", "Snake Bites", "Splinters", "Stomach", "Sunburn/burns", "Teeth", "Throat", "Wounds, Cuts"); $out = count($mypages); for ($counter = 0; $counter < count($mypages); $counter++) { $np = new Page(); // create new page object $np->template = "app_nav"; $np->parent = "/app_nav/"; // or id or page object $np->title = $mypages[$counter]; $np->save(); } return $out; } Edited April 12, 2017 by alan Added code 2 Link to comment Share on other sites More sharing options...
adrian Posted April 12, 2017 Share Posted April 12, 2017 @alan - another option would be to paste a list of page titles (one per row) into the Add mode screen of the BatchChildEditor module. No code needed 3 Link to comment Share on other sites More sharing options...
alan Posted April 12, 2017 Share Posted April 12, 2017 Thanks @adrian, I looked in the Modules list but totally missed your module (what am I like...). Bookmarked ✔ Link to comment Share on other sites More sharing options...
Robin S Posted April 12, 2017 Share Posted April 12, 2017 @alan, besides BatchChildEditor another handy module for this purpose is ImportPagesCSV. You select a template and parent, then in "Paste in CSV data" you just paste in a list of page titles and put 'title' on the first row (to indicate it is a list of titles). 1 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