Index: includes/common/functions.php
--- includes/common/functions.php
+++ includes/common/functions.php
@@ -1202,38 +1202,39 @@
  * @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 last child id
- * @uses wpdb::prepare() To prepare the query
- * @uses wpdb::get_var() To get the result of the query in a variable
- * @uses wp_cache_set() To set the cache for future use
+ * @uses WP_Query To get get the posts
  * @uses apply_filters() Calls 'bbp_get_public_child_last_id' with the child
  *                        id, parent id and post type
  * @return int The last active post_id
  */
 function bbp_get_public_child_last_id( $parent_id = 0, $post_type = 'post' ) {
-	global $wpdb;
 
 	// Bail if nothing passed
 	if ( empty( $parent_id ) )
 		return false;
 
 	// The ID of the cached query
-	$cache_id    = 'bbp_parent_' . $parent_id . '_type_' . $post_type . '_child_last_id';
 	$post_status = array( bbp_get_public_status_id() );
 
 	// Add closed status if topic post type
 	if ( $post_type == bbp_get_topic_post_type() )
 		$post_status[] = bbp_get_closed_status_id();
 
-	// Join post statuses together
-	$post_status = "'" . join( "', '", $post_status ) . "'";
-
 	// Check for cache and set if needed
-	$child_id = wp_cache_get( $cache_id, 'bbpress' );
-	if ( empty( $child_id ) ) {
-		$child_id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_parent = %d AND post_status IN ( {$post_status} ) AND post_type = '%s' ORDER BY ID DESC LIMIT 1;", $parent_id, $post_type ) );
-		wp_cache_set( $cache_id, $child_id, 'bbpress' );
-	}
+	$query = new WP_Query( array(
+		'fields'      => 'ids',
+		'post_parent' => $parent_id,
+		'post_status' => $post_status,
+		'post_type'   => $post_type,
+		
+		// Maybe change these later
+		'posts_per_page'         => 1,
+		'update_post_term_cache' => false,
+		'update_post_meta_cache' => false,
+		'ignore_sticky_posts'    => true,
+	) );
+	$child_id = array_shift( $query->posts );
+	unset( $query );
 
 	// Filter and return
 	return apply_filters( 'bbp_get_public_child_last_id', (int) $child_id, (int) $parent_id, $post_type );
@@ -1245,38 +1246,39 @@
  * @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 count
- * @uses wpdb::prepare() To prepare the query
- * @uses wpdb::get_var() To get the result of the query in a variable
- * @uses wp_cache_set() To set the cache for future use
+ * @uses WP_Query To get get the posts
  * @uses apply_filters() Calls 'bbp_get_public_child_count' with the child
  *                        count, parent id and post type
  * @return int The number of children
  */
 function bbp_get_public_child_count( $parent_id = 0, $post_type = 'post' ) {
-	global $wpdb;
 
 	// Bail if nothing passed
 	if ( empty( $parent_id ) )
 		return false;
 
 	// The ID of the cached query
-	$cache_id    = 'bbp_parent_' . $parent_id . '_type_' . $post_type . '_child_count';
 	$post_status = array( bbp_get_public_status_id() );
 
 	// Add closed status if topic post type
-	if ( $post_type == bbp_get_topic_post_type() )
+	if ( bbp_get_topic_post_type() == $post_type )
 		$post_status[] = bbp_get_closed_status_id();
 
-	// Join post statuses together
-	$post_status = "'" . join( "', '", $post_status ) . "'";
-
 	// Check for cache and set if needed
-	$child_count = wp_cache_get( $cache_id, 'bbpress' );
-	if ( empty( $child_count ) ) {
-		$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' );
-	}
+	$query = new WP_Query( array(
+		'fields'      => 'ids',
+		'post_parent' => $parent_id,
+		'post_status' => $post_status,
+		'post_type'   => $post_type,
+		
+		// Maybe change these later
+		'posts_per_page'         => -1,
+		'update_post_term_cache' => false,
+		'update_post_meta_cache' => false,
+		'ignore_sticky_posts'    => true,
+	) );
+	$child_count = $query->post_count;
+	unset( $query );
 
 	// Filter and return
 	return apply_filters( 'bbp_get_public_child_count', (int) $child_count, (int) $parent_id, $post_type );
@@ -1288,65 +1290,62 @@
  * @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
- * @uses wpdb::get_col() To get the result of the query in an array
- * @uses wp_cache_set() To set the cache for future use
+ * @uses WP_Query To get get the posts
  * @uses apply_filters() Calls 'bbp_get_public_child_ids' with the child ids,
  *                        parent id and post type
  * @return array The array of children
  */
 function bbp_get_public_child_ids( $parent_id = 0, $post_type = 'post' ) {
-	global $wpdb;
 
 	// Bail if nothing passed
 	if ( empty( $parent_id ) )
 		return false;
 
 	// The ID of the cached query
-	$cache_id    = 'bbp_parent_public_' . $parent_id . '_type_' . $post_type . '_child_ids';
 	$post_status = array( bbp_get_public_status_id() );
 
 	// Add closed status if topic post type
 	if ( $post_type == bbp_get_topic_post_type() )
 		$post_status[] = bbp_get_closed_status_id();
 
-	// Join post statuses together
-	$post_status = "'" . join( "', '", $post_status ) . "'";
-
 	// Check for cache and set if needed
-	$child_ids = wp_cache_get( $cache_id, 'bbpress' );
-	if ( empty( $child_ids ) ) {
-		$child_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_parent = %d AND post_status IN ( {$post_status} ) AND post_type = '%s' ORDER BY ID DESC;", $parent_id, $post_type ) );
-		wp_cache_set( $cache_id, $child_ids, 'bbpress' );
-	}
+	$query = new WP_Query( array(
+		'fields'      => 'ids',
+		'post_parent' => $parent_id,
+		'post_status' => $post_status,
+		'post_type'   => $post_type,
+		
+		// Maybe change these later
+		'posts_per_page'         => -1,
+		'update_post_term_cache' => false,
+		'update_post_meta_cache' => false,
+		'ignore_sticky_posts'    => true,
+	) );
+	$child_ids = !empty( $query->posts ) ? $query->posts : array();
+	unset( $query );
 
 	// Filter and return
 	return apply_filters( 'bbp_get_public_child_ids', $child_ids, (int) $parent_id, $post_type );
 }
+
 /**
  * Query the DB and get a the child id's of all 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
- * @uses wpdb::get_col() To get the result of the query in an array
- * @uses wp_cache_set() To set the cache for future use
+ * @uses WP_Query To get get the posts
  * @uses apply_filters() Calls 'bbp_get_public_child_ids' with the child ids,
  *                        parent id and post type
  * @return array The array of children
  */
 function bbp_get_all_child_ids( $parent_id = 0, $post_type = 'post' ) {
-	global $wpdb;
 
 	// Bail if nothing passed
 	if ( empty( $parent_id ) )
 		return false;
 
 	// The ID of the cached query
-	$cache_id    = 'bbp_parent_all_' . $parent_id . '_type_' . $post_type . '_child_ids';
 	$post_status = array( bbp_get_public_status_id() );
 
 	// Extra post statuses based on post type
@@ -1372,15 +1371,21 @@
 			break;
 	}
 
-	// Join post statuses together
-	$post_status = "'" . join( "', '", $post_status ) . "'";
-
 	// Check for cache and set if needed
-	$child_ids = wp_cache_get( $cache_id, 'bbpress' );
-	if ( empty( $child_ids ) ) {
-		$child_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_parent = %d AND post_status IN ( {$post_status} ) AND post_type = '%s' ORDER BY ID DESC;", $parent_id, $post_type ) );
-		wp_cache_set( $cache_id, $child_ids, 'bbpress' );
-	}
+	$query = new WP_Query( array(
+		'fields'      => 'ids',
+		'post_parent' => $parent_id,
+		'post_status' => 'any',
+		'post_type'   => $post_type,
+		
+		// Maybe change these later
+		'posts_per_page'         => -1,
+		'update_post_term_cache' => false,
+		'update_post_meta_cache' => false,
+		'ignore_sticky_posts'    => true,
+	) );
+	$child_ids = !empty( $query->posts ) ? $query->posts : array();
+	unset( $query );
 
 	// Filter and return
 	return apply_filters( 'bbp_get_all_child_ids', $child_ids, (int) $parent_id, $post_type );
Index: includes/core/cache.php
--- includes/core/cache.php
+++ includes/core/cache.php
@@ -145,22 +145,6 @@
 
 	do_action( 'bbp_clean_post_cache', $_post->ID, $_post );
 
-	// Child query types to clean
-	$post_types = array(
-		bbp_get_topic_post_type(),
-		bbp_get_forum_post_type(),
-		bbp_get_reply_post_type()
-	);
-
-	// Loop through query types and clean caches
-	foreach ( $post_types as $post_type ) {
-		wp_cache_delete( 'bbp_get_forum_'     . $_post->ID . '_reply_id',                              'bbpress' );
-		wp_cache_delete( 'bbp_parent_'        . $_post->ID . '_type_' . $post_type . '_child_last_id', 'bbpress' );
-		wp_cache_delete( 'bbp_parent_'        . $_post->ID . '_type_' . $post_type . '_child_count',   'bbpress' );
-		wp_cache_delete( 'bbp_parent_public_' . $_post->ID . '_type_' . $post_type . '_child_ids',     'bbpress' );
-		wp_cache_delete( 'bbp_parent_all_'    . $_post->ID . '_type_' . $post_type . '_child_ids',     'bbpress' );
-	}
-
 	// Invalidate parent caches
 	if ( ! empty( $_post->post_parent ) ) {
 		bbp_clean_post_cache( $_post->post_parent );
Index: includes/forums/functions.php
--- includes/forums/functions.php
+++ includes/forums/functions.php
@@ -1343,7 +1343,6 @@
  * @return int Topic hidden topic count
  */
 function bbp_update_forum_topic_count_hidden( $forum_id = 0, $topic_count = 0 ) {
-	global $wpdb;
 
 	// If topic_id was passed as $forum_id, then get its forum
 	if ( bbp_is_topic( $forum_id ) ) {
@@ -1359,9 +1358,23 @@
 	if ( !empty( $forum_id ) ) {
 
 		// Get topics of forum
-		if ( empty( $topic_count ) )
-			$topic_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_parent = %d AND post_status IN ( '" . join( '\',\'', array( bbp_get_trash_status_id(), bbp_get_spam_status_id() ) ) . "') AND post_type = '%s';", $forum_id, bbp_get_topic_post_type() ) );
+		if ( empty( $topic_count ) ) {
+			$query = new WP_Query( array(
+				'fields'      => 'ids',
+				'post_parent' => $forum_id,
+				'post_status' => array( bbp_get_trash_status_id(), bbp_get_spam_status_id() ),
+				'post_type'   => bbp_get_topic_post_type(),
 
+				// Maybe change these later
+				'posts_per_page'         => -1,
+				'update_post_term_cache' => false,
+				'update_post_meta_cache' => false,
+				'ignore_sticky_posts'    => true,
+			) );
+			$topic_count = $query->post_count;
+			unset( $query );
+		}
+
 		// Update the count
 		update_post_meta( $forum_id, '_bbp_topic_count_hidden', (int) $topic_count );
 	}
@@ -1391,7 +1404,6 @@
  * @return int Forum reply count
  */
 function bbp_update_forum_reply_count( $forum_id = 0 ) {
-	global $wpdb;
 
 	$forum_id = bbp_get_forum_id( $forum_id );
 	$children_reply_count = 0;
@@ -1407,9 +1419,22 @@
 	// Don't count replies if the forum is a category
 	$topic_ids = bbp_forum_query_topic_ids( $forum_id );
 	if ( !empty( $topic_ids ) ) {
-		$reply_count = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_parent IN ( " . join( ',', $topic_ids ) . " ) AND post_status = '%s' AND post_type = '%s';", bbp_get_public_status_id(), bbp_get_reply_post_type() ) );
+		$query = new WP_Query( array(
+			'fields'          => 'ids',
+			'post_parent__in' => $topic_ids,
+			'post_status'     => bbp_get_public_status_id(),
+			'post_type'       => bbp_get_reply_post_type(),
+
+			// Maybe change these later
+			'posts_per_page'         => -1,
+			'update_post_term_cache' => false,
+			'update_post_meta_cache' => false,
+			'ignore_sticky_posts'    => true,
+		) );
+		$reply_count = ! empty( $query->posts ) ? count( $query->posts ) : 0;
+		unset( $query );
 	} else {
-		$reply_count = 0;
+ 		$reply_count = 0;
 	}
 
 	// Calculate total replies in this forum
@@ -1726,63 +1751,49 @@
  */
 function bbp_forum_query_subforum_ids( $forum_id ) {
 	$subforum_ids = bbp_get_public_child_ids( $forum_id, bbp_get_forum_post_type() );
-	//usort( $subforum_ids, '_bbp_forum_query_usort_subforum_ids' );
 
 	return apply_filters( 'bbp_get_forum_subforum_ids', $subforum_ids, $forum_id );
 }
 
 /**
- * Callback to sort forum ID's based on last active time
- *
- * @since bbPress (r3789)
- * @param int $a First forum ID to compare
- * @param int $b Second forum ID to compare
- * @return Position change based on sort
- */
-function _bbp_forum_query_usort_subforum_ids( $a = 0, $b = 0 ) {
-	$ta = get_post_meta( $a, '_bbp_last_active_time', true );
-	$tb = get_post_meta( $b, '_bbp_last_active_time', true );
-	return ( $ta < $tb ) ? -1 : 1;
-}
-
-/**
  * Returns the forum's last reply id
  *
  * @since bbPress (r2908)
  *
  * @param int $forum_id Forum id
  * @param int $topic_ids Optional. Topic ids
- * @uses wp_cache_get() To check for cache and retrieve it
  * @uses bbp_forum_query_topic_ids() To get the forum's topic ids
- * @uses wpdb::prepare() To prepare the query
- * @uses wpdb::get_var() To execute the query and get the var back
  * @uses bbp_get_reply_post_type() To get the reply post type
- * @uses wp_cache_set() To set the cache for future use
  * @uses apply_filters() Calls 'bbp_forum_query_last_reply_id' with the reply id
  *                        and forum id
  */
-function bbp_forum_query_last_reply_id( $forum_id, $topic_ids = 0 ) {
-	global $wpdb;
+function bbp_forum_query_last_reply_id( $forum_id = 0, $topic_ids = 0 ) {
 
-	$cache_id = 'bbp_get_forum_' . $forum_id . '_reply_id';
-	$reply_id = (int) wp_cache_get( $cache_id, 'bbpress' );
+	// Validate forum
+	$forum_id = bbp_get_forum_id( $forum_id );
 
-	if ( empty( $reply_id ) ) {
+	// Get topic ID's if none were passed
+	if ( empty( $topic_ids ) )
+		$topic_ids = bbp_forum_query_topic_ids( $forum_id );
 
-		if ( empty( $topic_ids ) ) {
-			$topic_ids = bbp_forum_query_topic_ids( $forum_id );
-		}
+	// Check for cache and set if needed
+	$query = new WP_Query( array(
+		'fields'          => 'ids',
+		'post_parent__in' => $topic_ids,
+		'post_status'     => bbp_get_public_status_id(),
+		'post_type'       => bbp_get_reply_post_type(),
 
-		if ( !empty( $topic_ids ) ) {
-			$reply_id = (int) $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_parent IN ( " . join( ',', $topic_ids ) . " ) AND post_status = '%s' AND post_type = '%s' ORDER BY ID DESC LIMIT 1;", bbp_get_public_status_id(), bbp_get_reply_post_type() ) );
-			wp_cache_set( $cache_id, $reply_id, 'bbpress' ); // May be (int) 0
-		} else {
-			wp_cache_set( $cache_id, '0', 'bbpress' );
-		}
-	}
+		// Maybe change these later
+		'posts_per_page'         => 1,
+		'update_post_term_cache' => false,
+		'update_post_meta_cache' => false,
+		'ignore_sticky_posts'    => true,
+	) );
+	$reply_id = array_shift( $query->posts );
+	unset( $query );
 
-	return (int) apply_filters( 'bbp_get_forum_last_reply_id', (int) $reply_id, $forum_id );
-}
+ 	return (int) apply_filters( 'bbp_get_forum_last_reply_id', (int) $reply_id, $forum_id );
+ }
 
 /** Listeners *****************************************************************/
 
