Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to delete all user posts with a function in bbpress?

  • @serch1

    Participant

    Hello,

    I’ve been looking for a function to delete all user posts and topics from a user ID without luck. What I’m looking for is something like:

    delete_all_posts_and_topics(bbp_get_current_user_id());

    Anyone know if bbPress has a similar function or some clue to how implement it?

    Thank you a lot in advance.

Viewing 5 replies - 1 through 5 (of 5 total)
  • @robkk

    Moderator

    just delete the user from the WordPress backend

    go to users>all users then search for the user you want to delete

    hover around there avatar and name and you will a bunch of links which one of them says delete

    click that

    then the next screen which is added from bbPress which says

    [] delete all content

    [] attribute all content to: {some username}

    tick delete all content then confirm deletion

    @serch1

    Participant

    Hello Robkk! Thanks a lot for your detailed suggestion. I know this way to delete users from wordpress backend, but I’m looking for the function who does this in order to add a little code to my bbpress frontend 🙂

    @serch1

    Participant

    Well, what I want in wordpress is:

    
    add_action('delete_user', 'delete_posts_and_attachments');
    function delete_posts_and_attachments($user_id) {
        $args = array (
            'numberposts' => -1,
            'post_type' => 'any',
            'author' => $user_id
        );
        // get all posts by this user: posts, pages, attachments, etc..
        $user_posts = get_posts($args);
    
        if (empty($user_posts)) return;
    
        // delete all the user posts
        foreach ($user_posts as $user_post) {
            wp_delete_post($user_post->ID, true);
        }
    }

    But where and how can I delete posts from bbpress? any help will be appreciated :\

    @serch1

    Participant

    Sorry for the thread up, but hope there is a function by default to delete all user posts at bbpress forums. Someone know what function is?

    Thanks a lot in advance.

    @robkk

    Moderator

    Sorry for the thread up

    nah its two weeks its okay.

    as for your function , instead of doing a function because you would have to do it for every user you want to delete.

    how about do this so you can bulk delete the posts by the users in the replies/topics section.

    first create a new user named “deleted” or “removed” some kind of variation of that.

    then whenever you want to delete a user attribute all the content to that user you just created.

    then in the topics/replies section bulk delete the posts by searching the “deleted” user first. then clicking on the author link in the topics/replies section which should only show that users posts from there so you can bulk delete the posts.

    and to change the number of posts shown in one page of the topics/repies section change the default number to like say 75 or so.

    other than that maybe changing the post type of your function to reply or topic might make it work , also if you found the users id you want to delete and input into the id field.

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.
Skip to toolbar