bbp_delete_forum_topics( int $forum_id )
Delete all topics (and their replies) for a specific forum ID
Description
Parameters
- $forum_id
-
(Required)
Return
(If) forum is not valid
Source
File: bp-forums/forums/functions.php
2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 | function bbp_delete_forum_topics( $forum_id = 0 ) { // Validate forum ID $forum_id = bbp_get_forum_id( $forum_id ); if ( empty ( $forum_id ) ) return ; // Forum is being permanently deleted, so its content has go too // Note that we get all post statuses here $topics = new WP_Query( array ( 'suppress_filters' => true, 'post_type' => bbp_get_topic_post_type(), 'post_parent' => $forum_id , 'post_status' => array_keys ( get_post_stati() ), 'posts_per_page' => -1, 'nopaging' => true, 'fields' => 'id=>parent' ) ); // Loop through and delete child topics. Topic replies will get deleted by // the bbp_delete_topic() action. if ( ! empty ( $topics ->posts ) ) { foreach ( $topics ->posts as $topic ) { wp_delete_post( $topic ->ID, true ); } // 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.