• I added some coustom column by using manage_$postype_posts_custom_column and manage_$postype_posts_columns
    I’ve also registered the columns as sortable with manage_edit-$postype_sortable_columns
    now an up/down arrow appears next the fields title but when i click it nothing happens

    function my_admin_order( $query ) {
        if( ! is_admin() )
            return;
    
        $orderby = $query->get('orderby');
    
        if( 'description' == $orderby ) {
            $query->set('meta_key','description_1');
            $query->set('orderby','meta_value');
    		$query->set('order','DESC');
        }
    }
    add_action( 'pre_get_posts', 'my_admin_order' );

    post_request dump output:

    “SELECT SQL_CALC_FOUND_ROWS 3dwp_posts.* FROM 3dwp_posts INNER JOIN 3dwp_postmeta ON (3dwp_posts.ID = 3dwp_postmeta.post_id) WHERE 1=1 AND 3dwp_posts.post_type = ‘portfolio’ AND (3dwp_posts.post_status = ‘publish’ OR 3dwp_posts.post_status = ‘future’ OR 3dwp_posts.post_status = ‘draft’ OR 3dwp_posts.post_status = ‘pending’ OR 3dwp_posts.post_status = ‘private’) AND (3dwp_postmeta.meta_key = ‘description_1’ ) GROUP BY 3dwp_posts.ID ORDER BY 3dwp_posts.menu_order, 3dwp_posts.post_date DESC LIMIT 0, 20

    as you can see meda_value doesn’t appear inside ORDER BY statment

The topic ‘Sort ACF column in admin section’ is closed to new replies.