Skip to content

Instantly share code, notes, and snippets.

@artikus11
Created August 16, 2022 11:35
Show Gist options
  • Save artikus11/4b4b9b3b1dac0c192bd6b95ae42a68f6 to your computer and use it in GitHub Desktop.
Save artikus11/4b4b9b3b1dac0c192bd6b95ae42a68f6 to your computer and use it in GitHub Desktop.
Удаление всех миниатюр у отдельного типа записи
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