bbp_trash_forum_topics( int $forum_id )
Trash all topics inside a forum
Description
Parameters
- $forum_id
-
(Required)
Return
(If) forum is not valid
Source
File: bp-forums/forums/functions.php
function bbp_trash_forum_topics( $forum_id = 0 ) { // Validate forum ID $forum_id = bbp_get_forum_id( $forum_id ); if ( empty( $forum_id ) ) return; // Allowed post statuses to pre-trash $post_stati = implode( ',', array( bbp_get_public_status_id(), bbp_get_closed_status_id(), bbp_get_pending_status_id() ) ); // Forum is being trashed, so its topics and replies are trashed too $topics = new WP_Query( array( 'suppress_filters' => true, 'post_type' => bbp_get_topic_post_type(), 'post_parent' => $forum_id, 'post_status' => $post_stati, 'posts_per_page' => -1, 'nopaging' => true, 'fields' => 'id=>parent' ) ); // Loop through and trash child topics. Topic replies will get trashed by // the bbp_trash_topic() action. if ( !empty( $topics->posts ) ) { // Prevent debug notices $pre_trashed_topics = array(); // Loop through topics, trash them, and add them to array foreach ( $topics->posts as $topic ) { wp_trash_post( $topic->ID, true ); $pre_trashed_topics[] = $topic->ID; } // Set a post_meta entry of the topics that were trashed by this action. // This is so we can possibly untrash them, without untrashing topics // that were purposefully trashed before. update_post_meta( $forum_id, '_bbp_pre_trashed_topics', $pre_trashed_topics ); // Reset the $post global wp_reset_postdata(); } // Cleanup unset( $topics ); }
Changelog
Version | Description |
---|---|
bbPress (r3668) | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.