How to delete all posts for a specific custom post type

Add this script to you functions file, and replace {mypostname} by the name of the post type you want to delete.

<?php
$allposts = get_posts(array('post_type'=>'{mypostname}','numberposts'=>-1));
foreach ($allposts as $eachpost) wp_delete_post($eachpost->ID, true);
?>

Submit a Comment

Your email address will not be published.