Custom Fields
Re-Envisioned
Support MB Custom Taxonomy Taxonomy field is not saving the selected value

  • Creator
    Topic
  • #28292
    Resolved gparsec@gmail.com
    Participant

    Hello To All
    I am very new to the Metabox. But I have been able to figure out quite a few thing by my self but this one I am not able even after I read a similar post about it.
    I have a custom Taxonomy that works up to the point. The taxonomy entry's are visible including the Checkbox tree in the product page however the selected Checkbox is not holding its value.
    Any help much appreciated
    thank you

Viewing 9 replies - 1 through 9 (of 9 total)
  • Author
    Replies
  • #28311
    Long Nguyen
    Moderator

    Hi,

    If you use the field type taxonomy, you need to remove the default meta box of the taxonomy when editing the product.
    https://share.getcloudapp.com/4gu26Nkj

    #28318
    gparsec@gmail.com
    Participant

    Unfortunately the above solution did not fix the issue please advise
    Thank you

    #28323
    Long Nguyen
    Moderator

    Hi,

    Can you please share some screenshots of the issue? And share the code that creates the custom taxonomy, I will check it out.

    Follow this documentation to get PHP code if you use the Builder: https://docs.metabox.io/extensions/meta-box-builder/#getting-php-code

    #28326
    gparsec@gmail.com
    Participant
    <?php
    add_filter( 'rwmb_meta_boxes', 'your_prefix_function_name' );
    
    function your_prefix_function_name( $meta_boxes ) {
        $prefix = '';
    
    $meta_boxes[] = [
        'title'        => __( 'contryandregion', 'your-text-domain' ),
        'id'           => 'contryandregion',
        'post_types'   => ['product'],
        'autosave'     => true,
        'storage_type' => 'custom_table',
        'table'        => 'countryandregion',
        'fields'       => [
            [
                'name'              => __( 'Taxonomy Advanced', 'your-text-domain' ),
                'id'                => $prefix . 'taxonomy_advanced_cz9mzvgtnjt',
                'type'              => 'taxonomy_advanced',
                'label_description' => __( 'CandR', 'your-text-domain' ),
                'taxonomy'          => ['countryregion'],
                'field_type'        => 'checkbox_tree',
                'add_new'           => true,
            ],
        ],
    ];
    
    return $meta_boxes;
    
    }
    #28327
    gparsec@gmail.com
    Participant

    the screenshot shows the checkboxes selected but as soon I update the product page they get cleared from the check marks

    #28344
    Long Nguyen
    Moderator

    Hi,

    Thanks for the additional information.

    I see on your code, you are using the custom table to store field value. Can you please check the column key matches with the field ID taxonomy_advanced_cz9mzvgtnjt?

    Get more details on the documentation https://docs.metabox.io/extensions/mb-custom-table/.

    Or you can remove this setting to save field value in the default table of WordPress wp_postmeta

        'title'        => __( 'contryandregion', 'your-text-domain' ),
        'id'           => 'contryandregion',
        'post_types'   => ['product'],
        'autosave'     => true,
        'storage_type' => 'custom_table', //here
        'table'        => 'countryandregion', //here
    #28826
    PAUL TUNNICLIFFE
    Participant

    I had a similar issue and after a day trying to pin point things I believe it to be when a select tree field is held within a group the entered data is not saved back to the record.

    I created my fields using groups to be visually pleasing when entering data but found it not saved back.

    $meta_boxes[] = [
        'title'      => __( 'Vehicle Details2', 'gb_en' ),
        'id'         => 'vehicle_details_field_group_tyva2x-2',
        'post_types' => ['vehicle'],
        'fields'     => [
            [
                'name'   => __( 'Vehicle Classification', 'gb_en' ),
                'id'     => $prefix . 'vehicle_classification_group_9Uhfq72',
                'type'   => 'group',
                'fields' => [
                    [
                        'name'       => __( 'Vehicle Type', 'gb_en' ),
                        'id'         => $prefix . 'selecttree_vehicletype_field_99Ja3K2',
                        'type'       => 'taxonomy',
                        'taxonomy'   => ['vehicle_type_tax'],
                        'field_type' => 'select_tree',
                        'columns'    => 2,
                    ],
                    [
                        'name'       => __( 'Make & Model (Chassis/Base Vehicle)', 'gb_en' ),
                        'id'         => $prefix . 'selecttree_make_and_model_field_PUb47Z2',
                        'type'       => 'taxonomy',
                        'taxonomy'   => ['make_model_tax'],
                        'field_type' => 'select_tree',
                        'columns'    => 4,
                    ],
                    [
                        'name'       => __( 'Body Coachbuilder/Converter', 'gb_en' ),
                        'id'         => $prefix . 'selecttree_body_field_7hmMFt2',
                        'type'       => 'taxonomy',
                        'taxonomy'   => ['make_model_body_tax'],
                        'field_type' => 'select_tree',
                        'columns'    => 3,
                    ],
                ],
            ],
            [
                'name'          => __( 'Select', 'gb_en' ),
                'id'            => $prefix . 'select_vwzpyl0n06n',
                'type'          => 'taxonomy',
                'taxonomy'      => ['vehicle_type_tax'],
                'field_type'    => 'select_tree',
                'required'      => true,
                'admin_columns' => 'after',
                'columns'       => 2,
            ],
        ],
    ];
    
    return $meta_boxes;
    

    }

    I found the last field outside the group field did save data back.

    Therefore I moved the fields outside the group worked.

    $meta_boxes[] = [
        'title'      => __( 'Vehicle Details', 'gb_en' ),
        'id'         => 'vehicle_details_field_group_tyva2x',
        'post_types' => ['vehicle'],
        'fields'     => [
            [
                'name'          => __( 'Vehicle Type', 'gb_en' ),
                'id'            => $prefix . 'vehicle_classification_group_3HZ4uR',
                'type'          => 'taxonomy',
                'taxonomy'      => ['vehicle_type_tax'],
                'field_type'    => 'select_tree',
                'required'      => true,
                'admin_columns' => 'after title',
                'columns'       => 2,
            ],
            [
                'name'          => __( 'Make & Model (Chassis/Base Vehicle)', 'gb_en' ),
                'id'            => $prefix . 'selecttree_make_and_model_field_6FrTtD',
                'type'          => 'taxonomy',
                'taxonomy'      => ['make_model_tax'],
                'field_type'    => 'select_tree',
                'admin_columns' => 'after selecttree_vehicletype_field_99Ja3K',
                'columns'       => 4,
            ],
            [
                'name'       => __( 'Body Coachbuilder/Converter', 'gb_en' ),
                'id'         => $prefix . 'selecttree_body_field_8XqZar',
                'type'       => 'taxonomy',
                'taxonomy'   => ['make_model_body_tax'],
                'field_type' => 'select_tree',
                'required'   => true,
                'columns'    => 3,
            ],
            [
                'type' => 'divider',
            ],
    

    Is this a possible bug in the group or taxonomy/select tree fields?

    #28834
    Long Nguyen
    Moderator

    Hi Paul,

    The taxonomy field sets post terms like the category or tag, it does not work in the group. You can follow this topic to set post terms by coding https://trello.com/b/OCOz26GM/meta-boxs-public-roadmap

    Or use the taxonomy_advanced field instead, it will save the term ID as a post meta.

    #30533
    John Anderson
    Participant

    Hello,
    I am having a similar problem. I have a CPT called team-member and we want to identify the team member as being indigenous or not. So we use a taxonomy called "indigenous-team' where the user can select "Yes" or "No".

    Unfortunately when the user selects either and saves, the values are not saved. I have 2 other taxonomies attached to this CPT and they work fine.

    The PHP for the indigenous taxonomy is below. Any assistance would be gratefully accepted.

    
    <?php
    add_action( 'init', 'your_prefix_register_taxonomy' );
    function your_prefix_register_taxonomy() {
        $labels = [
            'name'                       => esc_html__( 'Indigenous Team', 'text-domain' ),
            'singular_name'              => esc_html__( 'Indigenous Team', 'text-domain' ),
            'menu_name'                  => esc_html__( 'Indigenous Team', 'text-domain' ),
            'all_items'                  => esc_html__( 'All Indigenous Team', 'text-domain' ),
            'edit_item'                  => esc_html__( 'Edit Indigenous Team', 'text-domain' ),
            'view_item'                  => esc_html__( 'View Indigenous Team', 'text-domain' ),
            'update_item'                => esc_html__( 'Update Indigenous Team', 'text-domain' ),
            'add_new_item'               => esc_html__( 'Add new Indigenous Team', 'text-domain' ),
            'new_item_name'              => esc_html__( 'New Indigenous Team', 'text-domain' ),
            'parent_item'                => esc_html__( 'Parent Indigenous Team', 'text-domain' ),
            'parent_item_colon'          => esc_html__( 'Parent Indigenous Team:', 'text-domain' ),
            'search_items'               => esc_html__( 'Search Indigenous Team', 'text-domain' ),
            'popular_items'              => esc_html__( 'Popular Indigenous Team', 'text-domain' ),
            'separate_items_with_commas' => esc_html__( 'Separate Indigenous Team with commas', 'text-domain' ),
            'add_or_remove_items'        => esc_html__( 'Add or remove Indigenous Team', 'text-domain' ),
            'choose_from_most_used'      => esc_html__( 'Choose most used Indigenous Team', 'text-domain' ),
            'not_found'                  => esc_html__( 'No Indigenous Team found', 'text-domain' ),
            'text_domain'                => esc_html__( 'text-domain', 'text-domain' ),
        ];
        $args = [
            'label'              => esc_html__( '', 'text-domain' ),
            'labels'             => $labels,
            'description'        => '',
            'public'             => true,
            'show_ui'            => true,
            'show_in_menu'       => true,
            'show_in_nav_menus'  => true,
            'meta_box_cb'        => true,
            'show_tagcloud'      => true,
            'show_in_quick_edit' => true,
            'show_admin_column'  => true,
            'show_in_rest'       => true,
            'hierarchical'       => false,
            'query_var'          => true,
            'sort'               => false,
            'rest_base'          => '',
            'rewrite'            => [
                'with_front'   => true,
                'hierarchical' => false,
            ],
        ];
        register_taxonomy( 'indigenous-team', ['team-member'], $args );
    }
    

    Thankyou

    John.

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