WordPress.org

Ready to get started?Download WordPress

Forums

Delete User Post if its role is Subscriber (2 posts)

  1. aotun1
    Member
    Posted 1 year 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);
    }
    }
    ?>

  2. vtxyzzy
    Member
    Posted 1 year ago #

    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);
          }
       }
    } ?>

Topic Closed

This topic has been closed to new replies.

About this Topic