write sorting instructions to query string