Jump to content

Can't bulk-publish unpublished pages?


MarcC
 Share

Recommended Posts

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

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);
  • Like 2
Link to comment
Share on other sites

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

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

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