1

I'm trying to auto-delete all BBpress replies of a user when someone's account is banned, but the wp_delete_post is not working with replies.

wp_delete_posts() returns a post object if it runs successfully, and it does do this with the reply, but the reply is not deleted from its respective topic!

$args = array (
        'numberposts' => -1,
        'post_type' => array('topic','reply'),
        'author' => $user_id
);
$user_posts = new WP_Query($args);
while ( $user_posts->have_posts() ) : $user_posts->the_post();
    wp_delete_post(get_the_ID(), true);    
endwhile;
4
  • 1
    How the above functionality is related with user account getting banned? Whats the hook you are using? Dec 9, 2013 at 17:14
  • The rest of the function works fine, this is the only problematic part. But just FYI I have a front-end button that my mods can click that deletes a user account via AJAX. I was adding this to that function bc deleting a user does not delete their replies (which may also be because of this bug!)
    – jetlej
    Dec 10, 2013 at 1:30
  • The above code works for me. wp_delete_posts() never returns a post object if it runs successfully rather its a wpdb object. Also can you please make it clear "it does do this with the reply" - do you mean delete here? Also do you have nested replies? Dec 10, 2013 at 3:41
  • It does return the wpdb object with replies, yes, but the replies still show and are even editable. Yes I do have threaded replies. Is that an issue?
    – jetlej
    Dec 11, 2013 at 21:06

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.