aotun1
Member
Posted 8 months ago #
In this code it delete all the post in all post type and in all user..
Help me please
<?php current_user_can('subscriber'); ?>
<?php
$args = array(
'post_type' => array('catsclass','dogsclass','dogbreed','catbreeder')
);
$posts = get_posts( $args );
if ($posts) {
// Delete all the Children of the Parent Page
foreach($posts as $post){
wp_delete_post($post->ID, true);
}
}
?>
BE SURE TO BACK UP FIRST!!
I believe that this is what you want (but it may not delete children, only the parent):
<?php $current_user = wp_get_current_user();
if ( $current_user->ID && current_user_can('subscriber' ) ) {
$args = array(
'post_type' => array('catsclass','dogsclass','dogbreed','catbreeder'),
'author' => $current_user->ID,
);
$posts = get_posts( $args );
if ($posts) {
// Delete all the Children of the Parent Page
foreach($posts as $post){
wp_delete_post($post->ID, true);
}
}
} ?>