Monthly Archives: December 2016

Change categories’ order

Needed the categories to be in certain order - not in alphabetical and not by id. It can be done by some plugin, but here is the way also through code:
 // change order of terms
   	function gto_forced_order($orderby) {

             switch (ICL_LANGUAGE_CODE){
   	      case("de"):
    	         $orderby = "FIELD(t.term_id, 465, 468,524,525,574,575, 600, 601,1240, 775, 777, 778, 841,843, 844)";
    	      break;
   	      case("fr"):
    	         $orderby = "FIELD(t.term_id,183, 184,203,204, 218, 219, 230, 231, 1239, 294, 296, 297, 306, 308,309)";
    	      break;
   	      case("ru"):
    	        $orderby "FIELD(t.term_id,954,955,974,975,989,990,1041,1042,1241,1145,1147,1375,1184,1186,1187)";
    	      break;
              case("es"):
    	         $orderby = "FIELD(t.term_id,834, 935,994,995,1009,1010,1021,1022,1242, 1165,1167,1168,1177,1179,1180 )";
    	       break;
               case("zh-hant"):
    	           $orderby = "FIELD(t.term_id,464, 467,526,527, 569, 570,609, 610,1238,795, 797, 798, 834, 836, 837)";
    	       break;
               case("ar"):
    	         $orderby = "FIELD(t.term_id,466, 469,528,529, 579, 580,591, 592,1243,815, 817, 818, 827, 829, 830)";
    	       break;
               default: 
     	         $orderby = "FIELD(t.term_id,125,95,97,121,33,32,124,99,37,36,96,122,123,94,34)";
     	        break;
              }

 
         return $orderby;
       }
add_filter('get_terms_orderby','gto_forced_order');

//original query
$tax_terms = get_terms( $tax, $tax_args );
gto_forced_order($tax_terms);
Just change the terms' IDs. Source as usual almighty Internet.