Created
August 16, 2022 11:35
-
-
Save artikus11/4b4b9b3b1dac0c192bd6b95ae42a68f6 to your computer and use it in GitHub Desktop.
Удаление всех миниатюр у отдельного типа записи
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function delete_all_attachments_by_post_type() { | |
global $wpdb; | |
$attachments = $wpdb->get_results( | |
"SELECT meta_value as att_id | |
FROM $wpdb->postmeta | |
INNER JOIN $wpdb->posts | |
ON ($wpdb->posts.ID = $wpdb->postmeta.post_id AND $wpdb->posts.post_type = 'courses') | |
WHERE meta_key = '_thumbnail_id'" | |
); | |
foreach ( $attachments as $attachment ) { | |
wp_delete_attachment( $attachment->att_id, true ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment