How to Delete Current Page Programatically

Permalink
Hi all

I am trying to delete the current page then navigate to another page:

$post = \Page::getCurrentPage();
$postHandle = $post->getCollectionHandle();
function trashPage() {
   $page = \Page::getByPath($postHandle);
   $page->moveToTrash();
}
function navToIndex() {
   ob_start();
   $url = '/members-1/members-forum/';
   while (ob_get_status()) 
   {
      ob_end_clean();
   }
   header( "Location: $url" );
}


I can see in the logs it's not getting the url slug because I see this:
Application admin Page "" at path "" Moved to trash

Any suggestions would be gratefully received please :)

Thanks
Dave

madesimplemedia
 
hutman replied on at Permalink Reply
hutman
You're not passing the $postHandle variable into your trashPage function.
madesimplemedia replied on at Permalink Reply
madesimplemedia
Thanks, well spotted I will try that out and let you know if I have any other issues :)