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
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.