You could easily query all the posts with a taxquery
, and loop through the results, deleting them one by one.
wp_delete_post()
gives you the option of moving a post to the trash, or forcing to delete it – so be careful with that.
To be sure that you delete the right posts, you can create a list of the posts to be deleted instead of deleting them directly.
Voila – here come the codes:
function f711_delete_all_posts_from_taxonomy() {
$args = array(
'orderby' => 'post_date',
'order' => 'DESC',
'numberposts' => -1,
'post_type' => 'post', // or whatever posttype you want to delete
'tax_query' => array(
array(
'taxonomy' => 'yourtaxonomy',
'field' => 'slug',
'terms' => 'slug-to-be-deleted'
)
)
);
$posts = get_posts( $args );
foreach( $posts as $thispost ) {
wp_delete_post( $thispost->ID, true ); //set second parameter to false to move the post to the trash
}
}