Jump to content

deleting hidden pages via API


froot
 Share

Recommended Posts

what's wrong with my code, why doesn't this work?!

$hidden = $pages->find("template=cast, status=hidden");

deleteHidden($hidden, $pages);

function deleteHidden($hidden, $pages) {
	foreach ($hidden as $item) {
		$pages->delete($item);
	}
}
Link to comment
Share on other sites

What happens when you run that code? The delete() method returns a boolean, try logging it to narrow down the problem.

Btw, you don’t need to pass $pages to your function. This should work too:

$hidden = $pages->find("template=cast, status=hidden");

deleteHidden($hidden);

function deleteHidden($hidden) {
	foreach ($hidden as $item) {
		$item->delete();
	}
}

Do these pages have children by any chance? In that case you should get an exception unless you move them away first, or specify that you want to delete them as well, using $item->delete(true).

  • Like 1
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...