Jump to content

Empty Trash via the API


Valery
 Share

Recommended Posts

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
Link to comment
Share on other sites

  • 3 years later...
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
Link to comment
Share on other sites

  • 2 years later...

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();

});

 

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

×
×
  • Create New...