Custom Fields
Re-Envisioned
Support Meta Box Builder single image field with the id _thumbnail_id is not showing after latest updates

  • Creator
    Topic
  • #18307
    Resolved brkard
    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.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Author
    Replies
  • #18323
    Anh 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
    brkard
    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 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 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.