| @@ -131,19 +131,24 @@ | ||
| 131 | 131 | */ |
| 132 | 132 | private function get_topic_participants( $topic_id, $max_shown ) { |
| 133 | 133 | global $wpdb; |
| 134 | 134 | |
| 135 | + // GROUP BY + MAX() instead of DISTINCT ... ORDER BY post_date, which | |
| 136 | + // MySQL 5.7+/8 rejects (ORDER BY column not in the SELECT list). | |
| 135 | 137 | // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching |
| 136 | 138 | $results = $wpdb->get_col( |
| 137 | 139 | $wpdb->prepare( |
| 138 | - "SELECT DISTINCT post_author | |
| 140 | + "SELECT post_author | |
| 139 | 141 | FROM {$wpdb->posts} |
| 140 | 142 | WHERE post_parent = %d |
| 141 | 143 | AND post_type = %s |
| 142 | 144 | AND post_status IN ( 'publish', 'closed' ) |
| 143 | - ORDER BY post_date DESC", | |
| 145 | + GROUP BY post_author | |
| 146 | + ORDER BY MAX( post_date ) DESC | |
| 147 | + LIMIT %d", | |
| 144 | 148 | $topic_id, |
| 145 | - bbp_get_reply_post_type() | |
| 149 | + bbp_get_reply_post_type(), | |
| 150 | + $max_shown > 0 ? $max_shown + 1 : 1000 | |
| 146 | 151 | ) |
| 147 | 152 | ); |
| 148 | 153 | |
| 149 | 154 | // Include the topic author at the beginning. |