Sometimes we will need to delete all of our posts, products, pages – that doesn’t matter – below you can find simple code, add it to the function.php file ( you can find it in your theme files – please keep in mind that you should always use child theme! )

function delete_all_posts() { 
     $posts= get_posts( array('post_type'=>'car','numberposts'=>-1) ); 

     foreach ($posts as $post) { 
         wp_delete_post( $post->ID, true ); 
     } 
} 
add_action('init', 'delete_all_posts');

In our example, we will delete all the custom post type “car” if you want to delete posts, you must change “car” on “post” – of course, if you have any other custom post type and you want to remove it, change that parameter to your value 🙂