$post_status = "'" . join( "', '", $post_status ) . "'";
// Check for cache and set if needed
if ( !$child_count = wp_cache_get( $cache_id, 'bbpress' ) ) {
$child_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_parent = %d AND post_status IN ( {$post_status} ) AND post_type = '%s';", $parent_id, $post_type ) );
wp_cache_set( $cache_id, $child_count, 'bbpress' );
}
// Filter and return
return apply_filters( 'bbp_get_public_child_count', (int) $child_count, (int) $parent_id, $post_type );
}
/**
* Query the DB and get a the child id's of public children
*
* @param int $parent_id Parent id
* @param string $post_type Post type. Defaults to 'post'
* @uses bbp_get_topic_post_type() To get the topic post type
* @uses wp_cache_get() To check if there is a cache of the children
* @uses wpdb::prepare() To prepare the query