bbPress: Add reverse order on topic replies

In bbPress this is to change the order of the replies under each topic and add a links to select the order.


function bbp_reverse_reply_order( $query = array() ) {
    $query['order'] = 'DESC';
	if( isset($_GET['order']) && in_array($_GET['order'],['desc','asc']) ){
		$query['order'] = $_GET['order'];
    return $query;

function bbp_add_order_topic_buttons(){
	echo '<div style="text-align: right; margin: 10px;">Sort by: <a href="' . add_query_arg(['order' => 'desc'], $wp->request) . '">Recent first</a> | <a href="' . add_query_arg(['order' => 'asc'], $wp->request) .'">Older first</a></div>';

Leave a Comment