说到 WordPress 的特色图像功能,相信大家都比较熟悉了,今天分享 批量删除所有文章的特色图像 的方法,或许有些朋友会用得上。将下面的代码添加到当前主题的 functions.php :
/**
* WordPress 批量删除所有文章的特色图像
* https://www.wpdaxue.com/bulk-remove-featured-images-from-posts.html
*/
global $wpdb;
$attachments = $wpdb->get_results( "
SELECT *
FROM $wpdb->postmeta
WHERE meta_key = '_thumbnail_id'
" );
foreach ( $attachments as $attachment ) {
wp_delete_attachment( $attachment->meta_value, true );
}
$wpdb->query( "
DELETE FROM $wpdb->postmeta
WHERE meta_key = '_thumbnail_id'
" ); |
/**
* WordPress 批量删除所有文章的特色图像
* https://www.wpdaxue.com/bulk-remove-featured-images-from-posts.html
*/
global $wpdb;
$attachments = $wpdb->get_results( "
SELECT *
FROM $wpdb->postmeta
WHERE meta_key = '_thumbnail_id'
" );
foreach ( $attachments as $attachment ) {
wp_delete_attachment( $attachment->meta_value, true );
}
$wpdb->query( "
DELETE FROM $wpdb->postmeta
WHERE meta_key = '_thumbnail_id'
" );
一旦你保存了 functions.php ,所有文章的特色图像都会被删除(只删除文章的特色图像设置数据,图片仍旧会保留在你的媒体库,不会删除),执行了一次以后,你应该删除这段代码,否则你将不可能给文章再添加特色图像(它会继续自动删除)。
参考资料:http://www.wpbeginner.com/wp-tutorials/how-to-bulk-remove-featured-images-from-posts-in-wordpress/
来源:
https://www.wpdaxue.com/bulk-remove-featured-images-from-posts.html
微信公众号
手机浏览(小程序)
Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57
Warning: get_headers(): Failed to enable crypto in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57
Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_33698.jpg): failed to open stream: operation failed in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57