Skip to content

Instantly share code, notes, and snippets.

View sabrina-zeidan's full-sized avatar

Sabrina Zeidan sabrina-zeidan

View GitHub Profile
@sabrina-zeidan
sabrina-zeidan / bulk_delete_posts.php
Last active September 13, 2021 22:27
Bulk delete all posts [Wordpress]
function bulk_delete_posts(){
$args = array( 'post_type' =>'post', 'posts_per_page' => -1, 'post_status' => 'any', 'fields' =>'ids');
$books = get_posts( $args );
foreach ($posts as $post) {
wp_delete_post( $post, true);
}
}
add_action( 'wp_head', 'bulk_delete_posts' );
@sabrina-zeidan
sabrina-zeidan / bulk_delete_comments.php
Last active May 27, 2020 03:14
Bulk delete all comments [Wordpress]
function bulk_delete_comments(){
$args = array('fields' => 'ids','number' => '','status' => 'all');
$comments = get_comments( $args );
foreach ($comments as $comment) {
wp_delete_comment( $comment, true);
}
}
add_action( 'wp_head', 'bulk_delete_comments' );
@sabrina-zeidan
sabrina-zeidan / bulk_delete_cpt.php
Created July 22, 2017 13:56
Bulk delete all custom posts [Wordpress]
function bulk_delete_books(){
$args = array( 'post_type' =>'book', 'posts_per_page' => -1, 'post_status' => 'any', 'fields' =>'ids');
$books = get_posts( $args );
foreach ($books as $book) {
wp_delete_post( $book, true);
}
}
add_action( 'wp_head', 'bulk_delete_books' );
@sabrina-zeidan
sabrina-zeidan / bulk_delete_revisions.php
Created July 22, 2017 13:58
Bulk delete revisions [Wordpress]
function bulk_delete_revisions(){
$args = array( 'post_type' =>'revision', 'posts_per_page' => -1, 'post_status' => 'any', 'fields' =>'ids');
$revisions = get_posts( $args );
foreach ($revisions as $revision) {
wp_delete_post( $revision, true);
}
}
add_action( 'wp_head', 'bulk_delete_revisions' );
@sabrina-zeidan
sabrina-zeidan / bulk_delete_spam_comments.php
Created July 22, 2017 14:00
Delete all spam comments [Wordpress]
function bulk_delete_spam_comments(){
$args = array('fields' => 'ids','number' => '','status' => 'spam');
$comments = get_comments( $args );
foreach ($comments as $comment) {
wp_delete_comment( $comment, true);
}
}
add_action( 'wp_head', 'bulk_delete_spam_comments' );
@sabrina-zeidan
sabrina-zeidan / bulk_convert_csv_to_xlsx.vbs
Last active July 22, 2017 14:54
This macros will bulk covert csv to xlsx in Excel. First, save csv to txt (just changing name.csv to name.txt in totalcommaner or similar, bulk in one click). Place to CSVfolder = "C:\csv\txt\" ,output will be here XlsFolder = "C:\csv\xlsx\"
Private Sub CommandButton2_Click()
Dim CSVfolder As String, _
XlsFolder As String, _
fname As String, _
wBook As Workbook
CSVfolder = "C:\csv\txt\"
XlsFolder = "C:\csv\xlsx\"
fname = Dir(CSVfolder & "*.txt")
@sabrina-zeidan
sabrina-zeidan / delete_tags_with_no_posts.php
Created July 22, 2017 14:59
Bulk delete tags with no posts (posts only check, may probable have cpt attached) [Wordpress]
function delete_tags_with_no_posts(){
$tags = get_tags( array('number' => 0,'hide_empty' => false));
foreach ( $tags as $tag ) {
$tag_id = $tag->term_id;
$args = array( 'post_type' => 'post', 'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => 'post_tag',
'field' => 'id',
'terms' => $tag_id
@sabrina-zeidan
sabrina-zeidan / delete_empty_tags.php
Created July 22, 2017 15:00
Bulk delete unused tags [Wordpress]
function delete_empty_tags(){
$tags = get_tags( array('number' => 0,'hide_empty' => false));
foreach ( $tags as $tag ) {
$tag_count = $tag->count;
if ($tag_count < 1 ){
wp_delete_term( $tag->term_id, 'post_tag' );
}
}
}
add_action( 'wp_head', 'delete_empty_tags' );
@sabrina-zeidan
sabrina-zeidan / delete_all_tags.php
Last active July 22, 2017 15:01
Bulk delete all tags [Wordpress]
function delete_all_tags(){
$tags = get_tags( array('number' => 0,'hide_empty' => false));
foreach ( $tags as $tag ) {
wp_delete_term( $tag->term_id, 'post_tag' );
}
}
add_action( 'wp_head', 'delete_all_tags' );
@sabrina-zeidan
sabrina-zeidan / delete_empty_terms.php
Last active December 28, 2022 22:17
Bulk delete empty taxonomy terms [Wordpress]
function delete_empty_terms(){
$taxonomy_name = 'city';
$terms = get_terms( array(
'taxonomy' => $taxonomy_name,
'hide_empty' => false
) );
foreach ( $terms as $term ) {
$term_count = $term->count;
if ($term_count < 1){ wp_delete_term($term->term_id, $taxonomy_name);
}