Index: includes/common/functions.php
===================================================================
--- includes/common/functions.php	(revision 5112)
+++ includes/common/functions.php	(working copy)
@@ -364,6 +364,51 @@
 }

 /**
+ * Fix post modified times on post save
+ *
+ * When a forum or topic is update, the post_modified and post_modified_gmt
+ * fields are updated. Since these fields are used for freshness data, we
+ * don't want to stomp out the current data. This keeps the post_modified(_gmt)
+ * fields at their current status, and moves the last edit time (in GMT) to post
+ * meta as '_bbp_last_edit_time_gmt'
+ *
+ * @since bbPress (rXXXX)
+ *
+ * @param array $data Post data
+ * @param array $postarr Original post array (includes post id)
+ * @uses bbp_get_topic_post_type() To get the topic post type
+ * @uses bbp_get_reply_post_type() To get the reply post type
+ * @uses bbp_is_post_request() To determine if we're in a POST request
+ * @uses update_post_meta() To update the '_bbp_last_edit_time_gmt' post meta field
+ * @uses get_post_field() To get the current post_modified(_gmt) fields
+ * @return array Data
+ */
+function bbp_fix_post_modified( $data = array(), $postarr = array() ) {
+
+	// Post is not being updated, return
+	if ( empty( $postarr['ID'] ) )
+		return $data;
+
+	// Post is not a forum or topic, return
+	if ( !in_array( $data['post_type'], array( bbp_get_forum_post_type(), bbp_get_topic_post_type() ) ) )
+		return $data;
+
+	// Are we editing?
+	if ( !bbp_is_post_request() && !in_array( $_POST['action'], array( 'bbp-edit-forum', 'bbp-edit-topic', 'editpost' ) ) )
+		return $data;
+
+	// Set the last edited time in post meta
+	update_post_meta( $postarr['ID'], '_bbp_last_edit_time_gmt', $data['post_modified_gmt'] );
+
+	// The post is being updated. It is a topic or a reply and is written by an anonymous user.
+	// Set the post_modified(_gmt) time back to their current values
+	$data['post_modified']     = get_post_field( 'post_modified',     $postarr['ID'], 'raw' );
+	$data['post_modified_gmt'] = get_post_field( 'post_modified_gmt', $postarr['ID'], 'raw' );
+
+	return $data;
+}
+
+/**
  * Check the date against the _bbp_edit_lock setting.
  *
  * @since bbPress (r3133)
@@ -1426,6 +1471,86 @@
 	return apply_filters( 'bbp_get_all_child_ids', $child_ids, (int) $parent_id, $post_type );
 }

+/**
+ * Updates the post_modified and post_modified_gmt fields of a topic/forum.
+ *
+ * This is just a helper function, with minimal data validation. Therefore,
+ * you will be better served using the appropriate wrapper funtions
+ * bbp_update_topic_post_modified() or bbp_update_forum_post_modified().
+ * Proper data validation should be performed before calling these functions.
+ * See bbp_update_forum_last_active_time() or bbp_update_topic_last_active_time()
+ * for examples on how to use.
+ *
+ * @since bbPress (rXXXX)
+ * @access private
+ *
+ * @global WPDB $wpdb
+ * @param int $post_id Forum/topic post_id
+ * @param string $post_modified MySQL timestamp 'Y-m-d H:i:s'
+ * @param string $post_modified_gmt MySQL timestamp 'Y-m-d H:i:s'. Defaults to false.
+ * @param string $type 'topic' or 'forum'
+ * @uses wpdb::update() To update the post_modified/post_modified_gmt fields
+ * @return int|bool The number of rows updated, or false on error.
+ */
+function bbp_update_post_modified_helper( $post_id, $post_modified, $post_modified_gmt = false, $type ) {
+
+	// Validate the post_id
+	$post_id   = call_user_func( "bbp_get_{$type}_id", $post_id );
+
+	// Get the post_type. This is to mitigate the likelihood of getting a valid
+	// post_id that's in the wrong post_type, and not the one we'd like to update
+	$post_type = call_user_func( "bbp_get_{$type}_post_type" );
+
+	// Make sure we have at least one date
+	if ( empty( $post_modified ) && empty( $post_modified_gmt ) ) {
+		return false;
+
+	// No post_modified_gmt provided
+	} elseif ( empty( $post_modified_gmt ) ) {
+		$post_modified     = date(   'Y-m-d H:i:s', strtotime( $post_modified ) );
+		$post_modified_gmt = gmdate( 'Y-m-d H:i:s', strtotime( $post_modified ) );
+
+	// No post_modified provided
+	} elseif ( empty( $post_modified ) ) {
+		$post_modified_gmt = gmdate( 'Y-m-d H:i:s', strtotime( $post_modified_gmt ) );
+		$post_modified     = date(   'Y-m-d H:i:s', strtotime( $post_modified_gmt ) );
+
+	// Looks good, but let's validate
+	} else {
+		$post_modified     = date(   'Y-m-d H:i:s', strtotime( $post_modified )     );
+		$post_modified_gmt = gmdate( 'Y-m-d H:i:s', strtotime( $post_modified_gmt ) );
+	}
+
+	// Grab the database global
+	global $wpdb;
+
+	// Update the, uh..., date?
+	return $wpdb->update(
+		// Table
+		$wpdb->posts,
+		// Field/value pairs to update
+		array(
+			'post_modified'     => $post_modified,
+			'post_modified_gmt' => $post_modified_gmt
+		),
+		// Where conditions
+		array(
+			'ID'        => $post_id,
+			'post_type' => $post_type
+		),
+		// Value formats for wpdb::prepare
+		array(
+			'%s',
+			'%s'
+		),
+		// Value formats for where conditions
+		array(
+			'%d',
+			'%s'
+		)
+	);
+}
+
 /** Globals *******************************************************************/

 /**
@@ -1531,7 +1656,7 @@

 		// Forum/Topic/Reply Feed
 		if ( isset( $query_vars['post_type'] ) ) {
-
+
 			// Supported select query vars
 			$select_query_vars = array(
 				'p'                      => false,
Index: includes/common/widgets.php
===================================================================
--- includes/common/widgets.php	(revision 5112)
+++ includes/common/widgets.php	(working copy)
@@ -743,8 +743,7 @@
 					'post_status'         => array( bbp_get_public_status_id(), bbp_get_closed_status_id() ),
 					'ignore_sticky_posts' => true,
 					'no_found_rows'       => true,
-					'meta_key'            => '_bbp_last_active_time',
-					'orderby'             => 'meta_value',
+					'orderby'             => 'modified',
 					'order'               => 'DESC',
 				);
 				break;
Index: includes/core/filters.php
===================================================================
--- includes/core/filters.php	(revision 5112)
+++ includes/core/filters.php	(working copy)
@@ -51,6 +51,9 @@
 // Fix post author id for anonymous posts (set it back to 0) when the post status is changed
 add_filter( 'wp_insert_post_data', 'bbp_fix_post_author', 30, 2 );

+// Fix post modified and post modified gmt time for forums and topics when the post is edited
+add_filter( 'wp_insert_post_data', 'bbp_fix_post_modified', 30, 2 );
+
 // Force comments_status on bbPress post types
 add_filter( 'comments_open', 'bbp_force_comment_status' );

Index: includes/forums/functions.php
===================================================================
--- includes/forums/functions.php	(revision 5112)
+++ includes/forums/functions.php	(working copy)
@@ -1128,8 +1128,7 @@
 		$post_vars = array(
 			'post_parent' => $forum_id,
 			'post_type'   => bbp_get_topic_post_type(),
-			'meta_key'    => '_bbp_last_active_time',
-			'orderby'     => 'meta_value',
+			'orderby'     => 'modified',
 			'numberposts' => 1
 		);

@@ -1283,6 +1282,25 @@
 }

 /**
+ * Updates the post_modified/post_modified_gmt fields of a forum.
+ *
+ * @since bbPress (rXXXX)
+ *
+ * @param int $post_id Forum post_id
+ * @param string $post_modified MySQL timestamp 'Y-m-d H:i:s'
+ * @param string $post_modified_gmt MySQL timestamp 'Y-m-d H:i:s'. Defaults to false.
+ * @uses bbp_update_post_modified_helper() To update the post_modified/post_modified_gmt fields
+ * @return int|bool The number of rows updated, or false on error.
+ */
+function bbp_update_forum_post_modified( $forum_id, $post_modified, $post_modified_gmt = false ) {
+
+	// Validate the forum_id
+	$topic_id = bbp_get_forum_id( $forum_id );
+
+	return bbp_update_post_modified_helper( $forum_id, $post_modified, $post_modified_gmt, 'forum' );
+}
+
+/**
  * Update the forums last active date/time (aka freshness)
  *
  * @since bbPress (r2680)
@@ -1305,8 +1323,10 @@
 		$new_time = get_post_field( 'post_date', bbp_get_forum_last_active_id( $forum_id ) );

 	// Update only if there is a time
-	if ( !empty( $new_time ) )
+	if ( !empty( $new_time ) ) {
 		update_post_meta( $forum_id, '_bbp_last_active_time', $new_time );
+		bbp_update_forum_post_modified( $forum_id, $new_time );
+	}

 	return (int) apply_filters( 'bbp_update_forum_last_active', $new_time, $forum_id );
 }
Index: includes/forums/template.php
===================================================================
--- includes/forums/template.php	(revision 5112)
+++ includes/forums/template.php	(working copy)
@@ -432,7 +432,7 @@
 	 *
 	 * @param int $forum_id Optional. Forum id
 	 * @uses bbp_get_forum_id() To get the forum id
-	 * @uses get_post_meta() To retrieve forum last active meta
+	 * @uses get_post_field() To retrieve forum last active meta
 	 * @uses bbp_get_forum_last_reply_id() To get forum's last reply id
 	 * @uses get_post_field() To get the post date of the reply
 	 * @uses bbp_get_forum_last_topic_id() To get forum's last topic id
@@ -448,7 +448,7 @@

 		// Verify forum and get last active meta
 		$forum_id    = bbp_get_forum_id( $forum_id );
-		$last_active = get_post_meta( $forum_id, '_bbp_last_active_time', true );
+		$last_active = get_post_field( 'post_modified', $forum_id );

 		if ( empty( $last_active ) ) {
 			$reply_id = bbp_get_forum_last_reply_id( $forum_id );
Index: includes/replies/functions.php
===================================================================
--- includes/replies/functions.php	(revision 5112)
+++ includes/replies/functions.php	(working copy)
@@ -870,7 +870,7 @@
 		update_post_meta( $reply_id, '_bbp_author_ip', bbp_current_author_ip(), false );

 		// Last active time
-		$last_active_time = current_time( 'mysql' );
+		$last_active_time = get_post_field( 'post_date', $reply_id );

 		// Walk up ancestors and do the dirty work
 		bbp_update_reply_walker( $reply_id, $last_active_time, $forum_id, $topic_id, false );
@@ -1399,7 +1399,7 @@
 		bbp_update_reply_to( $child->ID, $parent );

 	// Remove reply_to from moved reply
-	delete_post_meta( $move_reply->ID, '_bbp_reply_to' );
+	delete_post_meta( $move_reply->ID, '_bbp_reply_to' );

 	// It is a new topic and we need to set some default metas to make
 	// the topic display in bbp_has_topics() list
Index: includes/topics/functions.php
===================================================================
--- includes/topics/functions.php	(revision 5112)
+++ includes/topics/functions.php	(working copy)
@@ -887,7 +887,7 @@
 		update_post_meta( $topic_id, '_bbp_author_ip', bbp_current_author_ip(), false );

 		// Last active time
-		$last_active = current_time( 'mysql' );
+		$last_active = get_post_field( 'post_date', $topic_id );

 		// Reply topic meta
 		bbp_update_topic_last_reply_id      ( $topic_id, 0            );
@@ -965,7 +965,7 @@
 					'last_topic_id'      => $topic_id,
 					'last_reply_id'      => $reply_id,
 					'last_active_id'     => $active_id,
-					'last_active_time'   => 0,
+					'last_active_time'   => $last_active_time,
 					'last_active_status' => $topic_status
 				) );
 			}
@@ -2494,6 +2494,25 @@
 }

 /**
+ * Updates the post_modified/post_modified_gmt fields of a topic.
+ *
+ * @since bbPress (rXXXX)
+ *
+ * @param int $post_id Topic post_id
+ * @param string $post_modified MySQL timestamp 'Y-m-d H:i:s'
+ * @param string $post_modified_gmt MySQL timestamp 'Y-m-d H:i:s'. Defaults to false.
+ * @uses bbp_update_post_modified_helper() To update the post_modified/post_modified_gmt fields
+ * @return int|bool The number of rows updated, or false on error.
+ */
+function bbp_update_topic_post_modified( $topic_id, $post_modified, $post_modified_gmt = false ) {
+
+	// Validate the topic_id
+	$topic_id = bbp_get_topic_id( $topic_id );
+
+	return bbp_update_post_modified_helper( $topic_id, $post_modified, $post_modified_gmt, 'topic' );
+}
+
+/**
  * Update the topics last active date/time (aka freshness)
  *
  * @since bbPress (r2680)
@@ -2523,6 +2542,7 @@
 	// Update only if published
 	if ( !empty( $new_time ) ) {
 		update_post_meta( $topic_id, '_bbp_last_active_time', $new_time );
+		bbp_update_topic_post_modified( $topic_id, $new_time );
 	}

 	return apply_filters( 'bbp_update_topic_last_active_time', $new_time, $topic_id );
@@ -3453,7 +3473,7 @@
 					<guid><?php bbp_topic_permalink(); ?></guid>
 					<title><![CDATA[<?php bbp_topic_title(); ?>]]></title>
 					<link><?php bbp_topic_permalink(); ?></link>
-					<pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_post_meta( bbp_get_topic_id(), '_bbp_last_active_time', true ) ); ?></pubDate>
+					<pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_post_field( 'post_modified', bbp_get_topic_id() ) ); ?></pubDate>
 					<dc:creator><?php the_author() ?></dc:creator>

 					<?php if ( !post_password_required() ) : ?>
Index: includes/topics/template.php
===================================================================
--- includes/topics/template.php	(revision 5112)
+++ includes/topics/template.php	(working copy)
@@ -95,8 +95,7 @@
 	$default = array(
 		'post_type'      => bbp_get_topic_post_type(), // Narrow query down to bbPress topics
 		'post_parent'    => $default_post_parent,      // Forum ID
-		'meta_key'       => '_bbp_last_active_time',   // Make sure topic has some last activity time
-		'orderby'        => 'meta_value',              // 'meta_value', 'author', 'date', 'title', 'modified', 'parent', rand',
+		'orderby'        => 'modified',                // 'meta_value', 'author', 'date', 'title', 'modified', 'parent', rand',
 		'order'          => 'DESC',                    // 'ASC', 'DESC'
 		'posts_per_page' => bbp_get_topics_per_page(), // Topics per page
 		'paged'          => bbp_get_paged(),           // Page Number
@@ -223,8 +222,7 @@
 				$sticky_query = array(
 					'post_type'   => bbp_get_topic_post_type(),
 					'post_parent' => 'any',
-					'meta_key'    => '_bbp_last_active_time',
-					'orderby'     => 'meta_value',
+					'orderby'     => 'modified',
 					'order'       => 'DESC',
 					'include'     => $stickies
 				);
@@ -1716,7 +1714,7 @@
 	 *
 	 * @param int $topic_id Optional. Topic id
 	 * @uses bbp_get_topic_id() To get topic id
-	 * @uses get_post_meta() To get the topic lst active meta
+	 * @uses get_post_field() To get the topic lst active meta
 	 * @uses bbp_get_topic_last_reply_id() To get topic last reply id
 	 * @uses get_post_field() To get the post date of topic/reply
 	 * @uses bbp_convert_date() To convert date
@@ -1729,7 +1727,7 @@
 		$topic_id = bbp_get_topic_id( $topic_id );

 		// Try to get the most accurate freshness time possible
-		$last_active = get_post_meta( $topic_id, '_bbp_last_active_time', true );
+		$last_active = get_post_field( 'post_modified', $topic_id );
 		if ( empty( $last_active ) ) {
 			$reply_id = bbp_get_topic_last_reply_id( $topic_id );
 			if ( !empty( $reply_id ) ) {
