Support » Plugins » Hacks » Bulk delete images while still using them as thumbnail (featured)

  • nissimziv


    I would like to delete all the images that were uploaded to posts and pages of a WordPress site, while still using them as attachments/thumbnails (as featured images).
    That’s why, I can’t bulk delete them from the media library, only from within posts and pages.
    Since it’s a huge amount of images, I’d prefer using mysql command.
    The string of the images is always written as follows – <img xxxx>, where xxx is varied based on the img location and other details such as alt, width and height etc.
    The table is wp_posts and the fieldname is post_contnet
    The closest command I came across to is –
    UPDATE wp_posts SET post_content = REPLACE(post_content, ‘<img%>’, ”)
    WHERE post_content LIKE ‘<img%>’;
    It doesn’t work.
    Any clues?

Viewing 2 replies - 1 through 2 (of 2 total)
  • I wrote a plugin to bulk replace featured images. Take a look at

    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.

    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);
        set_transient('images_removed_from_past', 1);

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

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Bulk delete images while still using them as thumbnail (featured)’ is closed to new replies.