Custom Fields
Re-Envisioned
Support General How to change fields => id after created

  • Creator
    Topic
  • #30399
    Resolved flim
    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.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Author
    Replies
  • #30400
    flim
    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 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
    flim
    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 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
    flim
    Participant

    Many thanks 😀

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