How do I programatically empty trash?

I need to create an “Empty Trash” button inside my plugin. How would I do it using PHP code?

Related posts

Leave a Reply

2 comments

  1. This didn’t work for me. I had to do the following:

    $args = array(
    'posts_per_page'   => -1,
    'post_status'      => 'trash'
        );
    
    $trash = get_posts($args);
    
    foreach($trash as $post)
    {
        wp_delete_post($post->ID, true);      
    }