Getting Last Topic or Post Date
-
WordPress Version: 4.5.3
bbPress Version: 2.5.9
Website Link: http://www.sva.bc.ca/newforums/Hello,
After setting up bbPress I “imported” forum posts manually from an older system, setting the “Published On” date to match the date of each original topic/reply. I then found that bbPress’s “freshness” ignored this date and used the date/time I had manually added these posts.
So I installed the bbPress last post plugin ( https://en-gb.wordpress.org/plugins/bbp-last-post/ ) and modified it a little. The following code is what is currently being used, and is almost what I want:
<?php //this function changes the bbp freshness data (time since) into a last post date for forums function change_freshness_forum ($forum_id = 0 ) { // Verify forum and get last active meta $forum_id = bbp_get_forum_id( $forum_id ); $reply_id = bbp_get_forum_last_reply_id( $forum_id ); if ( !empty( $reply_id ) ) { $last_active_date = get_the_date( '', $reply_id ); } else { $topic_id = bbp_get_forum_last_topic_id( $forum_id ); if ( !empty( $topic_id ) ) { $last_active_date = get_the_date('', $topic_id ); } } if ( !empty( $reply_id ) ) { $last_active_time = get_the_time( '', $reply_id ); } else { if ( !empty( $topic_id ) ) { $last_active_time = get_the_time('', $topic_id ); } } $last_active_date = bbp_convert_date( $last_active_date ) ; $last_active_time = bbp_convert_date( $last_active_time ) ; $date_format = get_option( 'date_format' ); $time_format = get_option( 'time_format' ); $date= date_i18n( "{$date_format}", $last_active_date ); $time=date_i18n( "{$time_format}", $last_active_time ); $active_time = sprintf( _x( '%1$s at %2$s', 'date at time', 'bbp-last-post' ), $date, $time ); return $active_time ; } add_filter( 'bbp_get_forum_last_active', 'change_freshness_forum', 10, 2 ); //this function changes the bbp freshness data (time since) into a last post date for topics function change_freshness_topic ($last_active, $topic_id) { $topic_id = bbp_get_topic_id( $topic_id ); // Try to get the most accurate freshness date possible if ( empty( $last_active_date ) ) { $reply_id = bbp_get_topic_last_reply_id( $topic_id ); if ( !empty( $reply_id ) ) { $last_active_date = get_the_date( '', $reply_id ); } else { $last_active_date = get_the_date( '', $topic_id ); } } // Try to get the most accurate freshness time possible if ( empty( $last_active_time ) ) { $reply_id = bbp_get_topic_last_reply_id( $topic_id ); if ( !empty( $reply_id ) ) { $last_active_time = get_the_time( '', $reply_id ); } else { $last_active_time = get_the_time( '', $topic_id ); } } $last_active_date = bbp_convert_date( $last_active_date ) ; $last_active_time = bbp_convert_date( $last_active_time ) ; $date_format = get_option( 'date_format' ); $time_format = get_option( 'time_format' ); $date= date_i18n( "{$date_format}", $last_active_date ); $time=date_i18n( "{$time_format}", $last_active_time ); $active_time = sprintf( _x( '%1$s at %2$s', 'date at time', 'bbp-last-post' ), $date, $time ); return $active_time ; } add_filter( 'bbp_get_topic_last_active', 'change_freshness_topic', 10, 2 ); //This function changes the heading "Freshness" to the name created in Settings>bbp last post function change_translate_text( $translated_text ) { $text = 'Freshness' ; if ( $translated_text == $text ) { global $rlp_options; $translated_text = $rlp_options['heading_label']; } return $translated_text; } add_filter( 'gettext', 'change_translate_text', 20 );
The only problem now is that from the forum index view, the “Last Post” column will show the date of the most recent reply, even if there is a newer topic.
Is there a way to compare the dates and make sure the Last Post column displays the most recent topic or reply, whichever is newer?
Thanks!
- You must be logged in to reply to this topic.