Title: Multi_Sort Issue
Last modified: August 30, 2016

---

# Multi_Sort Issue

 *  Resolved [reggiegeografo](https://wordpress.org/support/users/reggiegeografo/)
 * (@reggiegeografo)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/multi_sort-issue/)
 * Hi,
 * I’ve been using the baseball.php for Netball because I needed extra fields such
   as RF (changed to Goals For), RA (changed to Goal Againts) and SO (changed to
   Goal Difference). I removed Pct and Games Behind as it is automatically generated.
   Everything is working fine. But one thing is not right when it comes to ranking.
   it ranks based on Match Won and Match Lost. It also ranks well based on Pts. 
   But I want it to rank as well based on SO (Shutouts on baseball but I changed
   it to Goal Difference) after sorting it based on won, lost and pts.
 * I did try to changed the codes function rankTeams( $league_id ) located on /sports/
   baseball.php but nothing happened.
 *     ```
       function rankTeams( $teams )
       	{
       		$won = $lost = array();
       		foreach ( $teams AS $key => $row ) {
       			$won[$key] = $row->won_matches;
       			$lost[$key] = $row->lost_matches;
       			$shutouts = $row->won_matches;
       					}
   
       		array_multisort( $won, SORT_DESC, $lost, SORT_ASC, $shutouts, SORT_DESC, $teams );
       		return $teams;
       	}
       ```
   
 * I am trying to change the ones on /lib/core.php but I cant. Please help me. Here
   is the code.
 *     ```
       function rankTeams( $league_id )
       	{
       		global $wpdb;
       		$league = $this->getLeague( $league_id );
   
       		if ( !isset($season) )
       			$season = $this->getSeason($league);
   
       		$season = is_array($season) ? $season['name'] : $season;
   
       		// rank Teams in groups
       		$groups = !empty($league->groups) ? explode(";", $league->groups) : array( '' );
   
       		foreach ( $groups AS $group ) {
       			$team_args = array("league_id" => $league_id, "season" => $season);
       			if ( !empty($group) ) $team_args["group"] = $group;
   
       			$teams = $teamsTmp = array();
       			foreach ( $this->getTeams( $team_args ) AS $team ) {
       				$team->diff = ( $team->diff > 0 ) ? '+'.$team->diff : $team->diff;
       				$team->points = array( 'plus' => $team->points_plus, 'minus' => $team->points_minus );
       				$team->points2 = array( 'plus' => $team->points2_plus, 'minus' => $team->points2_minus );
       				$team->winPercent = ($team->done_matches > 0) ? ($team->won_matches/$team->done_matches) * 100 : 0;
   
       				$teams[] = $team;
       				$teamsTmp[] = $team;
       			}
   
       			if ( !empty($teams) && $league->team_ranking == 'auto' ) {
       				if ( has_filter( 'rank_teams_'.$league->sport ) ) {
       					$teams = apply_filters( 'rank_teams_'.$league->sport, $teams );
       				} else {
       					foreach ( $teams AS $key => $row ) {
       						$points[$key] = $row->points['plus'] + $row->add_points;
       						$done[$key] = $row->done_matches;
       					}
   
       					array_multisort($points, SORT_DESC, $done, SORT_ASC, $teams);
       				}
       			}
                   updateRanking( $league_id, $season, $group, $teams, $teamsTmp );
       		}
   
       		return true;
       	}
       ```
   
 * Thanks in advance.
 * Geo
 * [https://wordpress.org/plugins/leaguemanager/](https://wordpress.org/plugins/leaguemanager/)

Viewing 1 replies (of 1 total)

 *  Thread Starter [reggiegeografo](https://wordpress.org/support/users/reggiegeografo/)
 * (@reggiegeografo)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/multi_sort-issue/#post-6619279)
 * I resolved it myself.
 * I edited the basketball.php which has the same ranking rules as Netball (Pts 
   first followed by the Points Difference) then I added 2 more tables to put the
   Goals For and Goals Againts in which I called the value of home_points and away_points
   then locked the input value so it will no longer be required.
 * If you want to know how I did it, just let me know.
 * Reggie

Viewing 1 replies (of 1 total)

The topic ‘Multi_Sort Issue’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/leaguemanager.svg)
 * [LeagueManager](https://wordpress.org/plugins/leaguemanager/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/leaguemanager/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/leaguemanager/)
 * [Active Topics](https://wordpress.org/support/plugin/leaguemanager/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/leaguemanager/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/leaguemanager/reviews/)

## Tags

 * [ranking](https://wordpress.org/support/topic-tag/ranking/)

 * 1 reply
 * 1 participant
 * Last reply from: [reggiegeografo](https://wordpress.org/support/users/reggiegeografo/)
 * Last activity: [10 years, 7 months ago](https://wordpress.org/support/topic/multi_sort-issue/#post-6619279)
 * Status: resolved