Skip to content

Instantly share code, notes, and snippets.

Avatar

Sabrina Zeidan sabrina-zeidan

View GitHub Profile
@sabrina-zeidan
sabrina-zeidan / bulk_delete_posts.php
Last active Dec 2, 2017
Bulk delete all posts [Wordpress]
View bulk_delete_posts.php
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
Bulk delete all comments [Wordpress]
View bulk_delete_comments.php
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 Jul 22, 2017
Bulk delete all custom posts [Wordpress]
View bulk_delete_cpt.php
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 Jul 22, 2017
Bulk delete revisions [Wordpress]
View bulk_delete_revisions.php
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 Jul 22, 2017
Delete all spam comments [Wordpress]
View bulk_delete_spam_comments.php
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 Jul 22, 2017
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\"
View bulk_convert_csv_to_xlsx.vbs
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 Jul 22, 2017
Bulk delete tags with no posts (posts only check, may probable have cpt attached) [Wordpress]
View delete_tags_with_no_posts.php
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 Jul 22, 2017
Bulk delete unused tags [Wordpress]
View delete_empty_tags.php
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 Jul 22, 2017
Bulk delete all tags [Wordpress]
View delete_all_tags.php
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 Jul 21, 2020
Bulk delete empty taxonomy terms [Wordpress]
View delete_empty_terms.php
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);
}
You can’t perform that action at this time.