Index: src/bp-activity/classes/class-bp-activity-activity.php
--- src/bp-activity/classes/class-bp-activity-activity.php
+++ src/bp-activity/classes/class-bp-activity-activity.php
@@ -339,137 +339,22 @@
 			'count_total'       => false,
 		) );
 
-		// Select conditions
+		// Metadata query?
+		$meta_query_sql = self::get_meta_query_sql( $r['meta_query'] );
+
+		// SELECT
 		$select_sql = "SELECT DISTINCT a.id";
 
+		// FROM
 		$from_sql   = " FROM {$bp->activity->table_name} a";
 
-		$join_sql   = '';
+		// JOIN
+		$join_sql   = ! empty( $meta_query_sql['join'] ) ? $meta_query_sql['join'] : '';
 
-		// Where conditions
-		$where_conditions = array();
+		// WHERE
+		$where_sql  = self::get_where_sql( $r, $select_sql, $from_sql, $join_sql, $meta_query_sql );
 
-		// Excluded types
-		$excluded_types = array();
-
-		// Scope takes precedence
-		if ( ! empty( $r['scope'] ) ) {
-			$scope_query = self::get_scope_query_sql( $r['scope'], $r );
-
-			// Add our SQL conditions if matches were found
-			if ( ! empty( $scope_query['sql'] ) ) {
-				$where_conditions['scope_query_sql'] = $scope_query['sql'];
-			}
-
-			// override some arguments if needed
-			if ( ! empty( $scope_query['override'] ) ) {
-				$r = self::array_replace_recursive( $r, $scope_query['override'] );
-			}
-
-		// Advanced filtering
-		} elseif ( ! empty( $r['filter_query'] ) ) {
-			$filter_query = new BP_Activity_Query( $r['filter_query'] );
-			$sql          = $filter_query->get_sql();
-			if ( ! empty( $sql ) ) {
-				$where_conditions['filter_query_sql'] = $sql;
-			}
-		}
-
-		// Regular filtering
-		if ( $r['filter'] && $filter_sql = BP_Activity_Activity::get_filter_sql( $r['filter'] ) ) {
-			$where_conditions['filter_sql'] = $filter_sql;
-		}
-
-		// Spam
-		if ( 'ham_only' == $r['spam'] ) {
-			$where_conditions['spam_sql'] = 'a.is_spam = 0';
-		} elseif ( 'spam_only' == $r['spam'] ) {
-			$where_conditions['spam_sql'] = 'a.is_spam = 1';
-		}
-
-		// Searching
-		if ( $r['search_terms'] ) {
-			$search_terms_like = '%' . bp_esc_like( $r['search_terms'] ) . '%';
-			$where_conditions['search_sql'] = $wpdb->prepare( 'a.content LIKE %s', $search_terms_like );
-		}
-
-		// Sorting
-		$sort = $r['sort'];
-		if ( $sort != 'ASC' && $sort != 'DESC' ) {
-			$sort = 'DESC';
-		}
-
-		// Hide Hidden Items?
-		if ( ! $r['show_hidden'] ) {
-			$where_conditions['hidden_sql'] = "a.hide_sitewide = 0";
-		}
-
-		// Exclude specified items
-		if ( ! empty( $r['exclude'] ) ) {
-			$exclude = implode( ',', wp_parse_id_list( $r['exclude'] ) );
-			$where_conditions['exclude'] = "a.id NOT IN ({$exclude})";
-		}
-
-		// The specific ids to which you want to limit the query
-		if ( ! empty( $r['in'] ) ) {
-			$in = implode( ',', wp_parse_id_list( $r['in'] ) );
-			$where_conditions['in'] = "a.id IN ({$in})";
-		}
-
-		// Process meta_query into SQL
-		$meta_query_sql = self::get_meta_query_sql( $r['meta_query'] );
-
-		if ( ! empty( $meta_query_sql['join'] ) ) {
-			$join_sql .= $meta_query_sql['join'];
-		}
-
-		if ( ! empty( $meta_query_sql['where'] ) ) {
-			$where_conditions[] = $meta_query_sql['where'];
-		}
-
-		// Process date_query into SQL
-		$date_query_sql = self::get_date_query_sql( $r['date_query'] );
-
-		if ( ! empty( $date_query_sql ) ) {
-			$where_conditions['date'] = $date_query_sql;
-		}
-
-		// Alter the query based on whether we want to show activity item
-		// comments in the stream like normal comments or threaded below
-		// the activity.
-		if ( false === $r['display_comments'] || 'threaded' === $r['display_comments'] ) {
-			$excluded_types[] = 'activity_comment';
-		}
-
-		// Exclude 'last_activity' items unless the 'action' filter has
-		// been explicitly set
-		if ( empty( $r['filter']['object'] ) ) {
-			$excluded_types[] = 'last_activity';
-		}
-
-		// Build the excluded type sql part
-		if ( ! empty( $excluded_types ) ) {
-			$not_in = "'" . implode( "', '", esc_sql( $excluded_types ) ) . "'";
-			$where_conditions['excluded_types'] = "a.type NOT IN ({$not_in})";
-		}
-
 		/**
-		 * Filters the MySQL WHERE conditions for the Activity items get method.
-		 *
-		 * @since BuddyPress (1.9.0)
-		 *
-		 * @param array  $where_conditions Current conditions for MySQL WHERE statement.
-		 * @param array  $r Parsed arguments passed into method.
-		 * @param string $select_sql Current SELECT MySQL statement at point of execution.
-		 * @param string $from_sql Current FROM MySQL statement at point of execution.
-		 * @param string $join_sql Current INNER JOIN MySQL statement at point of execution.
-		 */
-		$where_conditions = apply_filters( 'bp_activity_get_where_conditions', $where_conditions, $r, $select_sql, $from_sql, $join_sql );
-
-		// Join the where conditions together
-		$where_sql = 'WHERE ' . join( ' AND ', $where_conditions );
-
-		/**
 		 * Filters the preferred order of indexes for activity item.
 		 *
 		 * @since BuddyPress (1.6.0)
@@ -495,6 +380,12 @@
 		$page     = absint( $r['page']     );
 		$per_page = absint( $r['per_page'] );
 
+		// Sorting
+		$sort = $r['sort'];
+		if ( ( $sort !== 'ASC' ) && ( $sort !== 'DESC' ) ) {
+			$sort = 'DESC';
+		}
+
 		$retval = array(
 			'activities'     => null,
 			'total'          => null,
@@ -775,6 +666,131 @@
 	}
 
 	/**
+	 * Assemble the WHERE clause of a get() SQL statement.
+	 *
+	 * Used by BP_Activity_Activity::get() to create its WHERE clause.
+	 *
+	 * @since BuddyPress (2.3.0)
+	 *
+	 * @param array $args See {@link BP_Activity_Activity::get()} for more details.
+	 *
+	 * @return string WHERE clause.
+	 */
+	protected static function get_where_sql( $args = array(), $select_sql = '', $from_sql = '', $join_sql = '', $meta_query_sql = '' ) {
+		global $wpdb;
+
+		// Where conditions
+		$where_conditions = array();
+
+		// Excluded types
+		$excluded_types = array();
+
+		// Scope takes precedence
+		if ( ! empty( $args['scope'] ) ) {
+			$scope_query = self::get_scope_query_sql( $args['scope'], $args );
+
+			// Add our SQL conditions if matches were found
+			if ( ! empty( $scope_query['sql'] ) ) {
+				$where_conditions['scope_query_sql'] = $scope_query['sql'];
+			}
+
+			// override some arguments if needed
+			if ( ! empty( $scope_query['override'] ) ) {
+				$args = self::array_replace_recursive( $args, $scope_query['override'] );
+			}
+
+		// Advanced filtering
+		} elseif ( ! empty( $args['filter_query'] ) ) {
+			$filter_query = new BP_Activity_Query( $args['filter_query'] );
+			$sql          = $filter_query->get_sql();
+			if ( ! empty( $sql ) ) {
+				$where_conditions['filter_query_sql'] = $sql;
+			}
+		}
+
+		// Regular filtering
+		if ( ! empty( $args['filter'] ) && $filter_sql = self::get_filter_sql( $args['filter'] ) ) {
+			$where_conditions['filter_sql'] = $filter_sql;
+		}
+
+		// Spam
+		if ( 'ham_only' === $args['spam'] ) {
+			$where_conditions['spam_sql'] = 'a.is_spam = 0';
+		} elseif ( 'spam_only' === $args['spam'] ) {
+			$where_conditions['spam_sql'] = 'a.is_spam = 1';
+		}
+
+		// Searching
+		if ( $args['search_terms'] ) {
+			$search_terms_like = '%' . bp_esc_like( $args['search_terms'] ) . '%';
+			$where_conditions['search_sql'] = $wpdb->prepare( 'a.content LIKE %s', $search_terms_like );
+		}
+
+		// Hide Hidden Items?
+		if ( empty( $args['show_hidden'] ) ) {
+			$where_conditions['hidden_sql'] = "a.hide_sitewide = 0";
+		}
+
+		// Exclude specified items
+		if ( ! empty( $args['exclude'] ) ) {
+			$exclude = implode( ',', wp_parse_id_list( $args['exclude'] ) );
+			$where_conditions['exclude'] = "a.id NOT IN ({$exclude})";
+		}
+
+		// The specific ids to which you want to limit the query
+		if ( ! empty( $args['in'] ) ) {
+			$in = implode( ',', wp_parse_id_list( $args['in'] ) );
+			$where_conditions['in'] = "a.id IN ({$in})";
+		}
+
+		if ( ! empty( $meta_query_sql['where'] ) ) {
+			$where_conditions[] = $meta_query_sql['where'];
+		}
+
+		// Process date_query into SQL
+		$date_query_sql = self::get_date_query_sql( $args['date_query'] );
+
+		if ( ! empty( $date_query_sql ) ) {
+			$where_conditions['date'] = $date_query_sql;
+		}
+
+		// Alter the query based on whether we want to show activity item
+		// comments in the stream like normal comments or threaded below
+		// the activity.
+		if ( false === $args['display_comments'] || 'threaded' === $args['display_comments'] ) {
+			$excluded_types[] = 'activity_comment';
+		}
+
+		// Exclude 'last_activity' items unless the 'action' filter has
+		// been explicitly set
+		if ( empty( $args['filter']['object'] ) ) {
+			$excluded_types[] = 'last_activity';
+		}
+
+		// Build the excluded type sql part
+		if ( ! empty( $excluded_types ) ) {
+			$not_in = "'" . implode( "', '", esc_sql( $excluded_types ) ) . "'";
+			$where_conditions['excluded_types'] = "a.type NOT IN ({$not_in})";
+		}
+
+		/**
+		 * Filters the MySQL WHERE conditions for the Activity items get method.
+		 *
+		 * @since BuddyPress (1.9.0)
+		 *
+		 * @param array  $where_conditions Current conditions for MySQL WHERE statement.
+		 * @param array  $args Parsed arguments passed into method.
+		 * @param string $select_sql Current SELECT MySQL statement at point of execution.
+		 * @param string $from_sql Current FROM MySQL statement at point of execution.
+		 * @param string $join_sql Current INNER JOIN MySQL statement at point of execution.
+		 */
+		$where_conditions = apply_filters( 'bp_activity_get_where_conditions', $where_conditions, $args, $select_sql, $from_sql, $join_sql, $meta_query_sql );
+
+		// Join the where conditions together
+		return 'WHERE ' . join( ' AND ', $where_conditions );
+	}
+
+	/**
