• Hello, am trying to add filter to admin table for ACF fields
    this is the code, $_GET[‘custom_field_order’] will be the name of the field

    this code is actually working on my local machine but not on the server
    can you help me with this? or give me alternative solution
    thank you

    
    
    
    function my_author_filter_results($query){
        global $pagenow;
        if ( $pagenow === 'edit.php' ) {
            if(isset($_GET['custom_field_order'])){
                $custom_field_order = sanitize_text_field($_GET['custom_field_order']);
                $order = sanitize_text_field($_GET['order']) ;
                if($custom_field_order){
                    $query->query_vars['meta_key'] = $custom_field_order;
                    $query->query_vars['orderby'] = 'meta_value';
                    $query->query_vars['order'] = $order ?? 'asc';
                }
            }
        }
    
    }
    add_action('pre_get_posts','my_author_filter_results');

The topic ‘Custom fields filter in admin page’ is closed to new replies.