MarcC Posted August 1, 2013 Share Posted August 1, 2013 <?php include("./index.php"); /* Template changes in bulk -- let's publish all events */ $pa = wire("pages")->find("template=event"); foreach($pa as $p) { $p->setOutputFormatting(false); $p->removeStatus(Page::statusUnpublished); $p->save(); echo "Done with {$p->title}; {$p->status}<br>"; } The result of the code above is "Done with [event title]; 1" for every already published page, and no unpublished pages have been touched. What am I doing wrong? I'm trying to publish every page with the event template. This is modified code from a bulk editing thread. I noticed that somebody else said he couldn't get a similar thing to work because a module was causing problems. I wonder which one? Thanks. Link to comment Share on other sites More sharing options...
Wanze Posted August 1, 2013 Share Posted August 1, 2013 Problem is that you search only published pages. Try adding include=all to your selector, this will also give you unpublished pages. 3 Link to comment Share on other sites More sharing options...
MarcC Posted August 1, 2013 Author Share Posted August 1, 2013 Wow. I even tried "status>1" but I had no idea about include=all. Thanks! Link to comment Share on other sites More sharing options...
Soma Posted August 1, 2013 Share Posted August 1, 2013 A good way is to use more specific selector. 2 is parent ID of admin pages, and it will only return unpublished pages. $pages->find("template=event, has_parent!=2, status>=" . Page::statusUnpublished); 2 Link to comment Share on other sites More sharing options...
kongondo Posted August 2, 2013 Share Posted August 2, 2013 Or even... $pages->find("template=event, has_parent!=2, status=unpublished"); http://processwire.com/api/selectors/#access_control 2 Link to comment Share on other sites More sharing options...
MarcC Posted August 2, 2013 Author Share Posted August 2, 2013 has_parent!=2 OK...I don't understand that yet...has_parent!=2, so I guess has_parent is returning the ID of the parent? And the admin pages' parent is 2...how does that relate to being published or not? Link to comment Share on other sites More sharing options...
Soma Posted August 2, 2013 Share Posted August 2, 2013 OK...I don't understand that yet...has_parent!=2, so I guess has_parent is returning the ID of the parent? And the admin pages' parent is 2...how does that relate to being published or not? Ups, was a bit too late at night. It has nothing to do with unpublished but I usually trying to exclude admin pages when retrieving "all" pages, but it doesn't really make sense her as we already have template defined which no page under /processwire/ will usually have. Also kongondo is right with it's even better to use "status=unpublished" 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