How to bulk remove all the featured images in all articles
When I launched the local development today, the article image of the development site was not imported, but the featured image setting of the article still exists, causing has_post_thumbnail() to always judge the article with distinctive images, which brings inconvenience to the development. Just delete the featured images of all the articles in batches.
The implementation is simple, but you need to edit the sensitive file functions.php in the theme root directory and add the following code to the functions.php file:
Global $wpdb ;
$wpdb -> query ( "
DELETE FROM $wpdb->postmeta
WHERE meta_key = '_thumbnail_id'
" ) ;
Then refresh the next website page and the deletion will be performed.
Finally, it is very important: after refreshing the page and checking that the featured images of all the articles have been deleted, you must delete the code you just added, otherwise the featured images you set will be deleted, and the performance of the website will also be affected. ! ! !
Also, you can actually use the function to delete:
delete_post_meta_by_key ( '_thumbnail_id' ) ;
See the official documentation for more details: https://developer.wordpress.org/reference/functions/delete_post_meta_by_key/