spivurno
12/2/2016 - 12:44 PM

Gravity Perks // GP Unique ID // Force Sequential Unique IDs to be sorted Numerically w/ Gravity view

Gravity Perks // GP Unique ID // Force Sequential Unique IDs to be sorted Numerically w/ Gravity view

<?php
/**
 * Gravity Perks // GP Unique ID // Force Sequential Unique IDs to be sorted Numerically
 * Based on this article: http://docs.gravityview.co/article/112-how-to-force-numbers-to-sort-properly
 * http://gravitywiz.com/
 */
add_filter( 'gform_entry_post_save', function( $entry ) {

	$form_id         = 1525;
	$number_field_id = 3;
	$unique_field_id = 1;
	$max_range       = 100000;

	if( is_callable( 'gp_unique_id') && $entry['form_id'] == $form_id ) {
		$value = rgar( $entry, $unique_field_id ) / $max_range;
		GFAPI::update_entry_field( $entry['id'], $number_field_id, $value );
		$entry[ $number_field_id ] = $value;
	}

	return $entry;
} );