Define filterable and/or sortable admin columns in extened class

Support MB Admin Columns Define filterable and/or sortable admin columns in extened classResolved

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #27937
    JugiburJugibur
    Participant

    Hi,

    if I see correctly, I can't use fields in the admin columns that are inside a group field. At least the output remains empty for me.

    But that isnt't a big problem for me, because I have build a Plugin for extending a Custom Post Type following your example in the documentation:

    class Prefix_Custom_Admin_Columns extends \MBAC\Post {
        public function columns( $columns ) {
            $columns  = parent::columns( $columns );
            $position = '';
            $target   = '';
            $this->add( $columns, 'column_id', 'Column Title', $position, $target );
            // Add more if you want
            return $columns;
        }
        public function show( $column, $post_id ) {
            switch ( $column ) {
                case 'column_id':
                    echo 'Column content';
                    break;
                // More columns
            }
        }
    }
    

    Question is, how can I define columns that should be filterable and/or sortable?

    I tried to understand your code in the plugin classes and saw some methods, but I couldn't figured it out how to do a setup for such a column.

    Thanks in advance for any hint
    Juergen

    #27955
    Long NguyenLong Nguyen
    Moderator

    Hi,

    Thank you for reaching out.

    The custom admin columns do not support sorting by field value due to we don't know what's data type you add to the column. You can override the function sort() like show() to handle the query.
    https://prnt.sc/12jyse3

    #27957
    JugiburJugibur
    Participant

    Thanks for replay and the code, I will give it a try!

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.