How to change fields => id after created

Support General How to change fields => id after createdResolved

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #30399
    flimflim
    Participant

    Hi, I add a custom wysiwyg filed for WooCommerce Product, I want to change the fields id to something else.

    If I change the id value, the wysiwyg editor will be broke, how to change field id in the right way.

    #30400
    flimflim
    Participant

    This is how I create the field, I want to change the id "feature_list" to "highlight_features" but not work.

    add_filter( 'rwmb_meta_boxes', 'highlight_features_register_meta_boxes' );
    function highlight_features_register_meta_boxes( $meta_boxes ) {
        $prefix = '';
    
    $meta_boxes[] = [
        'title'   => 'Highlight Features',
        'id'      => 'highlight_features',
        'post_types' => 'product',
        'context' => 'normal',
        'fields'  => [
            [
                'type'  => 'wysiwyg',
                'name'  => 'Feature',
                'id'    => $prefix . 'feature_list',
        //'id'    => $prefix . 'highlight_features', <-- not work
            ],
        ],
    ];
    
    return $meta_boxes;
    }
    #30405
    Long NguyenLong Nguyen
    Moderator

    Hi,

    The meta box ID and field ID shouldn't be the same. You can try to change the meta box ID to another ID

    $meta_boxes[] = [
        'title'   => 'Highlight Features',
        'id'      => 'highlight_features_metabox',
        'post_types' => 'post',
        'context' => 'normal',
        'fields'  => [
            [
                'type'  => 'wysiwyg',
                'name'  => 'Feature',
                'id'    => $prefix . 'highlight_features',
            ],
        ],
    ];
    #30416
    flimflim
    Participant

    I can use a different id now. Thank you.

    I am new to WordPress and Meta Box, I wonder if I have some data input before, after change the metabox id, will those data become leftover in the database? If so, how to remove the previous id and data?

    #30420
    Long NguyenLong Nguyen
    Moderator

    Hi,

    The field ID and value are called post meta (meta key and meta value). Please follow this article to delete unused data on your site (include the orphaned post meta) https://gretathemes.com/clean-up-unused-data-wordpress/

    #30441
    flimflim
    Participant

    Many thanks 😀

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