| 913 | | ( SELECT `topic`.`ID`, '_bbp_last_active_id', MAX( `reply`.`ID` ) |
| 914 | | FROM `$wpdb->posts` AS `topic` INNER JOIN `$wpdb->posts` AS `reply` ON `topic`.`ID` = `reply`.`post_parent` |
| 915 | | WHERE `reply`.`post_status` = '{$pps}' AND `topic`.`post_type` = '{$tpt}' AND `reply`.`post_type` = '{$rpt}' |
| 916 | | GROUP BY `topic`.`ID` );" ) ) ) |
| | 913 | ( SELECT `topic`.`ID`, '_bbp_last_active_id', COALESCE( ( SELECT MAX( `reply`.`ID` ) |
| | 914 | FROM `$wpdb->posts` AS `reply` |
| | 915 | WHERE `topic`.`ID` = `reply`.`post_parent` AND `reply`.`post_status` = '{$pps}') , `topic`.`ID` ) |
| | 916 | FROM `$wpdb->posts` AS `topic` |
| | 917 | WHERE `topic`.`post_type` = '{$tpt}' );" ) ) ) |
| 921 | | ( SELECT `ID`, '_bbp_last_active_id', `ID` |
| 922 | | FROM `$wpdb->posts` AS `topic` LEFT JOIN `$wpdb->postmeta` AS `reply` |
| 923 | | ON `topic`.`ID` = `reply`.`post_id` AND `reply`.`meta_key` = '_bbp_last_active_id' |
| 924 | | WHERE `reply`.`meta_id` IS NULL AND `topic`.`post_type` = '{$tpt}' );" ) ) ) |
| | 922 | ( SELECT `topic`.`ID`, '_bbp_last_active_time', COALESCE( ( SELECT MAX( `reply`.`post_date` ) |
| | 923 | FROM `$wpdb->posts` AS `reply` |
| | 924 | WHERE `topic`.`ID` = `reply`.`post_parent` AND `reply`.`post_status` = '{$pps}') , `topic`.`post_date` ) |
| | 925 | FROM `$wpdb->posts` AS `topic` |
| | 926 | WHERE `topic`.`post_type` = '{$tpt}' );" ) ) ) |
| 927 | | // Give topics with replies their last update time. |
| 928 | | if ( is_wp_error( $wpdb->query( "INSERT INTO `$wpdb->postmeta` (`post_id`, `meta_key`, `meta_value`) |
| 929 | | ( SELECT `topic`.`ID`, '_bbp_last_active_time', MAX( `reply`.`post_date` ) |
| 930 | | FROM `$wpdb->posts` AS `topic` INNER JOIN `$wpdb->posts` AS `reply` ON `topic`.`ID` = `reply`.`post_parent` |
| 931 | | WHERE `reply`.`post_status` = '{$pps}' AND `topic`.`post_type` = '{$tpt}' AND `reply`.`post_type` = '{$rpt}' |
| 932 | | GROUP BY `topic`.`ID` );" ) ) ) |
| 933 | | return array( 8, sprintf( $statement, $result ) ); |
| 934 | | |
| 935 | | // Give topics without replies their last update time. |
| 936 | | if ( is_wp_error( $wpdb->query( "INSERT INTO `$wpdb->postmeta` (`post_id`, `meta_key`, `meta_value`) |
| 937 | | ( SELECT `ID`, '_bbp_last_active_time', `post_date` |
| 938 | | FROM `$wpdb->posts` AS `topic` LEFT JOIN `$wpdb->postmeta` AS `reply` |
| 939 | | ON `topic`.`ID` = `reply`.`post_id` AND `reply`.`meta_key` = '_bbp_last_active_time' |
| 940 | | WHERE `reply`.`meta_id` IS NULL AND `topic`.`post_type` = '{$tpt}' );" ) ) ) |
| 941 | | return array( 9, sprintf( $statement, $result ) ); |
| 942 | | |