Title: Adding order buttons
Last modified: October 21, 2019

---

# Adding order buttons

 *  Resolved [tapiohuuhaa](https://wordpress.org/support/users/tapiohuuhaa/)
 * (@tapiohuuhaa)
 * [6 years, 7 months ago](https://wordpress.org/support/topic/adding-order-buttons/)
 * I would like to add 1-3 buttons to the forum topics listing in order to change
   the default order. I would code it to changed template, if I would know what 
   functions to use.
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fadding-order-buttons%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Author [Robin W](https://wordpress.org/support/users/robin-w/)
 * (@robin-w)
 * [6 years, 7 months ago](https://wordpress.org/support/topic/adding-order-buttons/#post-12051052)
 * answered in bbpress support forum, but very complicated to do
 *  Thread Starter [tapiohuuhaa](https://wordpress.org/support/users/tapiohuuhaa/)
 * (@tapiohuuhaa)
 * [6 years, 7 months ago](https://wordpress.org/support/topic/adding-order-buttons/#post-12054195)
 * This was not very complicated because I needed just three options. In fact when
   used default order I just prevented changing the order:
 * > `function my_custom_display_topic_index_query () {
   >  global $_GET,$_COOKIE; 
   > if(isset($_GET[‘myOrderBy’]) && !($_GET[‘myOrderBy’]==’default’)){ // if seleted
   > default, it just doon’t change anything or returns original listing order $
   > args[‘orderby’] =$_GET[‘myOrderBy’]; if($_GET[‘myOrderBy’]==’post_date’) $args[‘
   > order’] = ‘DESC’; else $args[‘order’] = ‘ASC’; }elseif(isset($_COOKIE[‘myOrderBy’])&&!(
   > $_COOKIE[‘myOrderBy’]==’default’)){ $args[‘orderby’] =$_COOKIE[‘myOrderBy’];
   > if($_COOKIE[‘myOrderBy’]==’post_date’) $args[‘order’] = ‘DESC’; else $args[‘
   > order’] = ‘ASC’; } return $args; }
   > if((isset($_GET[‘myOrderBy’]) && !($_GET[‘myOrderBy’]==’default’)))
   >  add_filter(‘
   > bbp_before_has_topics_parse_args’, ‘my_custom_display_topic_index_query’ );
   > elseif(isset($_COOKIE[‘myOrderBy’]) && !($_COOKIE[‘myOrderBy’]==’default’) &&!
   > isset($_GET[‘myOrderBy’])) add_filter(‘bbp_before_has_topics_parse_args’, ‘
   > my_custom_display_topic_index_query’ );
   > function printSelections(){
   >  global $_SERVER,$_GET,$_COOKIE; $selval=$_GET[‘
   > myOrderBy’]; $extraClass=’ active-button’; if(isset($selval)){ if($selval==’
   > post_date’) $extraClass2=$extraClass; elseif($selval==’post_title’) $extraClass3
   > =$extraClass; elseif($selval==’default’) $extraClass1=$extraClass; }elseif(
   > isset($_COOKIE[‘myOrderBy’])){ if($_COOKIE[‘myOrderBy’]==’post_date’) $extraClass2
   > =$extraClass; elseif($_COOKIE[‘myOrderBy’]==’post_title’) $extraClass3=$extraClass;
   > elseif($_COOKIE[‘myOrderBy’]==’default’) $extraClass1=$extraClass; }elseif(!
   > isset($selval) && !isset($_COOKIE[‘myOrderBy’])){$extraClass1=$extraClass;}
   > $currentUrl=’[https://&#8217](https://&#8217); . $_SERVER[‘HTTP_HOST’]. $_SERVER[‘
   > REQUEST_URI’]; $myUrlPos= stripos($currentUrl,’?’); if($myUrlPos) $currentUrl
   > =substr($currentUrl,0,$myUrlPos); return ‘<div class=”queries”> <table class
   > =”querytable” style=”width:auto!important;margin:0!important;padding:0!important;
   > border-width:0″><tr> <th>Järjestys:</th><td style=”padding:0 3px!important”
   > > <a id=”orderbutton1″ class=”subscription-toggle orderbutton’.$extraClass1.'”
   > href=”‘.$currentUrl.’?myOrderBy=default” style=”padding-left:6px!important”
   > >Kommentoitu</a></td><td style=”padding:0 3px 0 0!important”><a id=”orderbutton2″
   > class=”subscription-toggle orderbutton’.$extraClass2.'” href=”‘.$currentUrl.’?
   > myOrderBy=post_date” style=”padding-left:6px!important”>Aloitettu</a></td><
   > td style=”padding:0 3px 0 0!important”><a id=”orderbutton3″ class=”subscription-
   > toggle orderbutton’.$extraClass3.'” href=”‘.$currentUrl.’?myOrderBy=post_title”
   > style=”padding-left:6px!important”>Otsikko</a></td></tr></table></div>’; }`
 * Works as expected here:
    [https://www.sanaristikkofoorumi.net/wordpress/forums/forum/sanaristikot/suomen-kuvalehti/](https://www.sanaristikkofoorumi.net/wordpress/forums/forum/sanaristikot/suomen-kuvalehti/)
    -  This reply was modified 6 years, 7 months ago by [tapiohuuhaa](https://wordpress.org/support/users/tapiohuuhaa/).

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Adding order buttons’ is closed to new replies.

 * ![](https://ps.w.org/bbp-style-pack/assets/icon-256x256.jpg?rev=2706563)
 * [bbp style pack](https://wordpress.org/plugins/bbp-style-pack/)
 * [Support Threads](https://wordpress.org/support/plugin/bbp-style-pack/)
 * [Active Topics](https://wordpress.org/support/plugin/bbp-style-pack/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/bbp-style-pack/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/bbp-style-pack/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [tapiohuuhaa](https://wordpress.org/support/users/tapiohuuhaa/)
 * Last activity: [6 years, 7 months ago](https://wordpress.org/support/topic/adding-order-buttons/#post-12054195)
 * Status: resolved