Jump to content

Recommended Posts

Posted

Hello everybody,

I am trying to empty the Trash through the API. What's the best way to accomplish that?

Also, does

$pages->get("parent=/trash/"); 

work?

Posted (edited)

That will get the pages. one page [and you need include all {of course}, see below].you then need to delete them :D...

Edited for corrections..see below...slow Tuesday kongondo!

Edited by kongondo
Posted

To delete pages you may use delete. http://cheatsheet.processwire.com/?filter=delete (must have been still in m clipboard :P )

$pages->delete($page, true); // recursive with children

$pages->delete($page);

$page->delete();

To get pages from the trash you would need include all

$pa = $pages->find("parent=/trash/,include=all");

$pages->get() will give you only 1 page. http://cheatsheet.processwire.com/?filter=pages-%3Eget

  • Like 6
Posted

I did not try the following code, but I think it should work:

foreach ($pages->find("status>=" . Page::statusTrash) as $p) {

$p->delete();

}

Edit: Soma was faster again..
  • Like 4
  • 3 years later...
Posted
On 8/20/2013 at 7:46 AM, Valery said:

I am trying to empty the Trash through the API. What's the best way to accomplish that?


I know this is ancient, but I just had to do this and discovered a very simple way :)

$pages->emptyTrash();

Maybe this is newish?

  • Like 3
Posted
8 hours ago, adrian said:


I know this is ancient, but I just had to do this and discovered a very simple way :)


$pages->emptyTrash();

Maybe this is newish?

Nice one! Seems it's been around since 2.7...so, yeah, newish

  • Like 3
  • 2 years later...
Posted

I'm trying to empty the trash with a hook but it's not working:

$wire->addHook('LazyCron::everyMinute', function() {

  $trashed_pages = wire('pages')->find("parent=/trash/, include=all");

  if(count($trashed_pages)) {
    $trashed_pages->emptyTrash();
  }

});

 

Posted

I figured it out:

$wire->addHook('LazyCron::every4Weeks', function() {

  $trashed_pages = wire('pages')->find("parent=/trash/, include=all");

  if(count($trashed_pages)) {
    wire('pages')->emptyTrash();
  }

});

Should I use the above or just the below simpler version?

$wire->addHook('LazyCron::every4Weeks', function() {

  wire('pages')->emptyTrash();

});

 

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
×
×
  • Create New...