amritansh
9/26/2017 - 5:44 AM

Deletes all the posts of a posttype

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;
}