Last active
September 9, 2020 11:31
-
-
Save fabriziofeitosa/9347025ac58ccca0a8084678a6d40a55 to your computer and use it in GitHub Desktop.
(WP) Apagar todas as postagens ligadas a um "Post Type" e anexos ligados a cada postagem
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
<?php | |
// Buscar todos os posts de 'post_type' = X | Aqui definido como 'property' | |
$allposts= get_posts( array('post_type'=>'property','numberposts'=>-1) ); | |
// Percorrer posts | |
foreach ($allposts as $post) { | |
// Excluir primeiro os anexos ligados ao Post | |
$attachments = get_attached_media( '', $post->ID ); | |
foreach ($attachments as $attachment) { | |
wp_delete_attachment( $attachment->ID, true ); | |
} | |
// Deletar posts | |
wp_delete_post( $post->ID, true ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment