single image field with the id _thumbnail_id is not showing after latest updates

Support MB Builder single image field with the id _thumbnail_id is not showing after latest updatesResolved

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #18307
    brkardbrkard
    Participant

    H.

    I have a single image field with the id _thumbnail_id . I am using this field to insert fetaured image.

    After the updates this field is not showing if i name this fields id as " _thumbnail_id "

    If i change the field name to _thumbnail_id2 it is working.

    Do you have any idea about this ?

    Thanks.

    #18323
    Anh TranAnh Tran
    Keymaster

    Hi,

    Do you have featured image enable for that post type? If yes, then maybe there are 2 fields with the same ID and the default featured image might override the Meta Box field.

    #19333
    brkardbrkard
    Participant

    Hi.

    Actually i have disabled the featured image. And it was working. But it stops working after some updates. I am not sure which updates, wordpress or metabox ?

    Anyway. , i was using it and stil want to use a single image metabox field for featured image. I was using field name as _thumbnail_id . And this is not working now.

    I will be happy if you check this or help me to do this with another way. How can i use a single image metabox field to insert a featured image.

    Thanks.

    #19337
    Long NguyenLong Nguyen
    Moderator

    Hi,

    After removing the default featured image and use the single image field with the ID _thumbnail_id to save value for this meta key, it works as well with the latest version of Meta Box v5.2.10. Please try again with my sample code

    // Remove the featured image
    add_action( 'init', function () {
        remove_post_type_support( 'post', 'thumbnail' );
    } );
    
    add_filter( 'rwmb_meta_boxes', function ( $meta_boxes ) {
        // Get the current post thumbnail and set as the default value for the single image field.
        $post_id = filter_input( INPUT_GET, 'post', FILTER_SANITIZE_NUMBER_INT );
        $post_thumbnail = get_post_meta( $post_id, '_thumbnail_id' );
    
        $meta_boxes[] = [
            'title'      => 'Featured image',
            'post_types' => 'post',
            'fields'     => [
                // Register a single image field
                [
                    'type' => 'single_image',
                    'id'   => '_thumbnail_id', // This is the must!
                    'name' => 'Fake featured image',
                    'std'  => $post_thumbnail,
                ],
            ],
        ];
    
        return $meta_boxes;
    } );

    Let me know how it goes.

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