Correctly sort values by an external order field (see #5322)