WPIntell

Source evidence

Filter by numeric field

Admin Columns for ACF Fields · support · 2020-07-16T13:36:00+00:00

complaintsentiment
mediumseverity
0.92relevance
2replies
Evidence linked to opportunitycommercial context

Proof Health

Open evidence

Commercial opportunities need traceable source links before they are treated as build-worthy.

5 / 31 rows with source links

16.1% of this page's analysis has direct source links.

0 build-decision rows missing links

0 rows here require auditable proof before promotion.

26 rows with no attached evidence

0 rows have source counts but still need direct links.

Conversation

support
kopiczkos unresolved
Hello, I was trying to filter post items by column, that uses a numeric ACF field and found a bug. Filtering by numeric field caused 10 appearing before 2, 31 before 4 etc. I’ve made a change in acf_admin_columns.php when setting: $query->set('orderby', 'meta_value'); to: if($query->query['orderby'] == 'acf_nights_hidden') { $query->set('orderby', 'meta_value_num'); } else { $query->set('orderby', 'meta_value'); } where nights_hidden is my acf numeric field name. It helps in my case but I think it could be great if you can fix it generally :). Best, Sebastian. Hey kopiczkos, hm…interesting issue and good idea…I will look into integrating this within one of the next versions… Thanks and best regards, Florian Hallo Florian, i had a similar Problem with Sorting. I have set the fix from @kopiczkos outside of the Plugin. The advantage is, that the Plugin is already updateable and the changes will not be overwriten on an Update. I post the code here. Maybe someone will find it helpful: function event_admin_column_sort($query) { $acf_active = (function_exists('acf_get_field_groups') && function_exists('acf_get_fields')); $acf_columns_active = class_exists('FleiACFAdminColumns'); $is_valid_admin_screen = (bool) false; if (function_exists('get_current_screen') && $screen = get_current_screen()) { $is_valid_admin_screen = ($screen->base == 'edit' && $screen->post_type) || ($screen->base == 'edit-tags' && $screen->taxonomy); } if (is_admin() && $acf_columns_active && $acf_active && $is_valid_admin_screen && $query->query_vars && isset($query->query_vars['orderby'])) { if($query->query['orderby'] == 'acf_eventon_field_related_course') { $query->set('orderby', 'meta_value_num'); } else { $query->set('orderby', 'meta_value'); } } return $query; } add_action('pre_get_posts', 'event_admin_column_sort', 999); Another suggestion could be, that it could be helpful to set Class-Methods is_acf_active and is_valid_admin_screen to be public to use it outside the plugin. And a great feature would be, that the user can set on a selection field, if it should be sorted by value or by title of the saved option. But at last: Great Plugin! Many Thanks. @flei

Comments

2 shown
Florian Eickhorst 2020-08-07T15:07:00+00:00

Hey kopiczkos, hm…interesting issue and good idea…I will look into integrating this within one of the next versions… Thanks and best regards, Florian

anonymized-15531514 2020-09-02T09:23:00+00:00

Hallo Florian, i had a similar Problem with Sorting. I have set the fix from @kopiczkos outside of the Plugin. The advantage is, that the Plugin is already updateable and the changes will not be overwriten on an Update. I post the code here. Maybe someone will find it helpful: function event_admin_column_sort($query) { $acf_active = (function_exists('acf_get_field_groups') && function_exists('acf_get_fields')); $acf_columns_active = class_exists('FleiACFAdminColumns'); $is_valid_admin_screen = (bool) false; if (function_exists('get_current_screen') && $screen = get_current_screen()) { $is_valid_admin_screen = ($screen->base == 'edit' && $screen->post_type) || ($screen->base == 'edit-tags' && $screen->taxonomy); } if (is_admin() && $acf_columns_active && $acf_active && $is_valid_admin_screen && $query->query_vars && isset($query->query_vars['orderby'])) { if($query->query['orderby'] == 'acf_eventon_field_related_course') { $query->set('orderby', 'meta_value_num'); } else { $query->set('orderby', 'meta_value'); } } return $query; } add_action('pre_get_posts', 'event_admin_column_sort', 999); Another suggestion could be, that it could be helpful to set Class-Methods is_acf_active and is_valid_admin_screen to be public to use it outside the plugin. And a great feature would be, that the user can set on a selection field, if it should be sorted by value or by title of the saved option. But at last: Great Plugin! Many Thanks. @flei