bbp_delete_forum_topics( int $forum_id )
Delete all topics (and their replies) for a specific forum ID
Description Description
Parameters Parameters
- $forum_id
-
(Required)
Return Return
(If) forum is not valid
Source Source
File: includes/forums/functions.php
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( 'fields' => 'id=>parent', 'post_type' => bbp_get_topic_post_type(), 'post_parent' => $forum_id, 'post_status' => array_keys( get_post_stati() ), 'posts_per_page' => -1, // Performance 'nopaging' => true, 'suppress_filters' => true, 'update_post_term_cache' => false, 'update_post_meta_cache' => false, 'ignore_sticky_posts' => true, 'no_found_rows' => true ) ); // 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 Changelog
Version | Description |
---|---|
2.1.0 | Introduced. |