This code is to order by ACF fields in admin page. It actually filter by custom field but not ordering it.

the data inside the fields is string and not numeric, so i think orderby meta_value is correct. And i make sure that this key is not empty, i tried all these terms (desc,DESC,asc,ASC)

function my_author_filter_results($query){
    global $pagenow;
    if ( $pagenow === 'edit.php' ) {
            $custom_field_order = sanitize_text_field($_GET['custom_field_order']);
            $order = sanitize_text_field($_GET['order']) ;
                $query->query_vars['meta_key'] = $custom_field_order;
                $query->query_vars['orderby'] = 'meta_value';
                $query->query_vars['order'] =  strtoupper($order);


PS: it works fine on my localhost

1 Answer 1


After searching i found the issue, another plugin called (Post type order) that uses drag and drop, ignored the sorting

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.