Forcing numbers to sort properly

Let's say you have a drop-down field on your form with choices ranging from 1 to 10 or greater.

Screenshot showing the options for a drop down field inside the form editor

And you try to sort your View by this field:

Screenshot showing the View Settings panel inside the View editor

GravityView can't sort text-based fields as if they were numbers. So your View will probably appear like this, with the Order column not correctly sorted.

Screenshot of a View

There's a way to force GravityView to interpret those fields as if they were numbers by using a special filter:

add_filter( 'gravityview_search_criteria', 'gravityview_force_numeric_sort', 10, 3 );
function gravityview_force_numeric_sort( $criteria, $form_ids = array(), $context_view_id = 0 ) {
	$criteria['sorting']['is_numeric'] = true;
	return $criteria;
}
		

Click here to see here where to add this code snippet.

This will force the View to sort these choices as if they were numbers:

This filter doesn't work for sorting a secondary field, unfortunately.

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us