private function _replaceOrderBy (ElementQuery $query, $search = false)
	{
		$nextOrder = [];

		foreach ((array) $query->orderBy as $order => $sort)
		{
			if ($order === 'distance' && $search) $nextOrder[$search] = $sort;
			elseif ($order !== 'distance') $nextOrder[$order] = $sort;
		}

		$query->orderBy($nextOrder);
	}
private function _replaceOrderBy (ElementQuery $query, $search = false)
	{
		$nextOrder = [];

		foreach ((array) $query->orderBy as $order => $sort)
		{
			if ($order === 'distance' && $search) $nextOrder[$search] = $sort;
			elseif ($order !== 'distance') $nextOrder[$order] = $sort;
		}

		$query->orderBy($nextOrder);
	}
private function _replaceOrderBy ( ElementQuery $ query , $ search = false ) { $ nextOrder = [ ] ; foreach ( ( array ) $ query -> orderBy as $ order => $ sort ) { if ( $ order === 'distance' && $ search ) $ nextOrder [ $ search ] = $ sort ; elseif ( $ order !== 'distance' ) $ nextOrder [ $ order ] = $ sort ; } $ query -> orderBy ( $ nextOrder ) ; }
Will replace the distance search with the correct query if available,
or otherwise remove it.

@param ElementQuery $query
@param bool         $search
Will replace the distance search with the correct query if available or otherwise remove it .