Quantcast
Channel: Topic Tag: MySQL | WordPress.org
Viewing all articles
Browse latest Browse all 5530

nissimziv on "Bulk delete images while still using them as thumbnail (featured)"

$
0
0

Thank you Hinjiriyo!
I am going to test this plugin. Very useful indeed.

Actually, I found a way to mass delete images, therefore would like to post it for anyone who will face the same issue in the future.
(Hinjiriyo: can you add this functionality to your new plugin??)
Go to functions.php and add this function to the end.

<?php
function remove_images_form_past_posts() {
  if ( get_transient('images_removed_from_past') ) return;
  $posts = get_posts('nopaging=1');
  if ( $posts ) {
    foreach ( $posts as $post ) {
      $newcontent = preg_replace('/<img[^>]+\>/i', '', $post->post_content);
      $newpost = array( 'ID' => $post->ID, 'post_content' => $newcontent);
      wp_update_post($newpost);
    }
    set_transient('images_removed_from_past', 1);
  }
}

add_action('admin_init','remove_images_form_past_posts');
?>

After that:
1. Reload dashboard (F5) and see that all images were deleted.
2. Delete the above function for functions.php .


Viewing all articles
Browse latest Browse all 5530

Trending Articles