Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forcing two fields to sort numerically with a filter doesn't work #1759

Closed
rafaehlers opened this issue Oct 19, 2022 · 2 comments
Closed

Forcing two fields to sort numerically with a filter doesn't work #1759

rafaehlers opened this issue Oct 19, 2022 · 2 comments

Comments

@rafaehlers
Copy link
Contributor

rafaehlers commented Oct 19, 2022

The only way at this moment (GV 2.15) to force text-based fields to force as they were numbers is by using the following filter:

function force_is_numeric_gravityview_search_criteria( $criteria, $form_ids = array(), $context_view_id = 0 ) {
	$criteria['sorting']['is_numeric'] = true;
	return $criteria;
}

add_filter( 'gravityview_search_criteria', 'force_is_numeric_gravityview_search_criteria', 10, 3 );

This filter works as proved here: https://debug.try.gravitykit.com/view/drop-down-sorting-test/?cache

However, it doesn't work when setting sort on a secondary field:

image

image

Related: https://docs.gravitykit.com/article/112-forcing-numbers-to-sort-properly

gk-migrate-debug.try.gravitykit.com-2024-08-26-1724694417.zip

@rafaehlers rafaehlers changed the title Forcing two fields to sorting numerically with a filter doesn't work Forcing two fields to sort numerically with a filter doesn't work Oct 19, 2022
@rafaehlers
Copy link
Contributor Author

@mrcasual mrcasual added Enhancement and removed Bug labels Aug 27, 2024
mrcasual added a commit that referenced this issue Aug 27, 2024
This allows for more granular control of sorting parameters for each
when fetching View entries.
mrcasual added a commit that referenced this issue Aug 27, 2024
This allows for more granular control of sorting parameters for each
when fetching View entries.
mrcasual added a commit that referenced this issue Aug 28, 2024
This implements #1759.

To test, use this filter:

```
add_filter( 'gk/gravityview/view/entries/query/sorting-parameters', function ( $params ) {
	foreach ( $params as &$field ) {
		$field['is_numeric'] = true;
	}

	return $params;
} );
```

[GravityMigrate
data](https://github.com/user-attachments/files/16765603/gk-migrate-debug.try.gravitykit.com-2024-08-26-1724694417.zip).



💾 [Build
file](https://www.dropbox.com/scl/fi/5ik2t3mr6pk8lx4m91wg5/gravityview-2.27.1-81f6fa655.zip?rlkey=35eq2s9hyesjukmd0lsrvrp4n&dl=1)
(81f6fa6).
@rafaehlers
Copy link
Contributor Author

This is now working. Doc updated with the new filter: https://docs.gravitykit.com/article/112-forcing-numbers-to-sort-properly

Customer notified ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants