Link an Admin Column's value to post's edit page

Support MB Admin Columns Link an Admin Column's value to post's edit page

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #35372
    AnLipAnLip
    Participant

    Hi,
    I have created a custom field that is a "Single Image". I gave it the ID "_thumbnail_id" so that it replaces the native WP featured image. I selected it to "Show as an Admin column" which it does.

    Now, how to make that thumbnail linked to the post's edit page ? It is the most obvious thing my client will want to click on (title is secondary).

    The subject has already been addressed here but was never given an answer (appart from use another plugin) :
    https://support.metabox.io/topic/how-to-link-an-admin-column-value-to-the-post-edit-screen/

    Thank you.

    #35379
    Long NguyenLong Nguyen
    Moderator

    Hi,

    You can create a custom columns to show the image and link to the editing post. For example:

    add_action( 'init', 'prefix_add_custom_columns', 20 );
    function prefix_add_custom_columns() {
        class Prefix_Custom_Admin_Columns extends \MBAC\Post {
            public function columns( $columns ) {
                $columns  = parent::columns( $columns );
                $position = '';
                $target   = '';
                $this->add( $columns, '_thumbnail_id', 'Column Title', $position, $target );
                // Add more if you want
                return $columns;
            }
            public function show( $column, $post_id ) {
                switch ( $column ) {
                    case '_thumbnail_id':
                        $image = rwmb_meta( '_thumbnail_id', array( 'size' => 'thumbnail' ), $post_id );
                        if( !empty( $image ) ) {
                            echo '<a href="' . get_edit_post_link( $post_id ) . '"><img src="' . $image['url'] . '" /></a>';    
                        }
                        break;
                    // More columns
                }
            }
        }
        
        new Prefix_Custom_Admin_Columns( 'post', array() );
    }

    Read more on the documentation https://docs.metabox.io/extensions/mb-admin-columns/#custom-admin-columns

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