Skip to content

Instantly share code, notes, and snippets.

@amrt0510
Created September 26, 2017 05:44
Show Gist options
  • Save amrt0510/f27cf5d94e7fa35fe7ab0241d3e2fd1c to your computer and use it in GitHub Desktop.
Save amrt0510/f27cf5d94e7fa35fe7ab0241d3e2fd1c to your computer and use it in GitHub Desktop.
Deletes all the posts of a posttype
/*
* Deletes all the posts of a posttype
*/
delete_all_posts_of_a_postype($posttype, $posts_per_page);
function delete_all_events() {
global $post;
$args = array(
'post_type' => $posttype,
'post_status' => 'publish',
'posts_per_page' => $posts_per_page,
'paged' => 1
);
$query = new WP_Query($args);
if ($query->have_posts()) : while ($query->have_posts()) : $query->the_post();
wp_delete_post($post->ID);
endwhile;
endif;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment