Created
September 26, 2017 05:44
-
-
Save amrt0510/f27cf5d94e7fa35fe7ab0241d3e2fd1c to your computer and use it in GitHub Desktop.
Deletes all the posts of a posttype
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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