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
(@anonymized-15531514)
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