Custom Fields
Re-Envisioned
Support MB Blocks Not show Taxonomy field values in MB Blocks

  • Creator
    Topic
  • #23427
    Resolved DANIEL FITIPALDO R.
    Participant

    Hi,
    I have a problem using a taxonomy field in MB Blocks. I create a block containing a field with 'type' => 'taxonomy'. I can set a value for this field in the block editor, but when I leave the post and then return I do not see the previously set value even when the value in the database is well stored. Can you help me?
    This is the custom taxonomy:

    add_action( 'init', 'your_prefix_register_taxonomy' );
    function your_prefix_register_taxonomy() {
        $labels = [
            'name'                       => esc_html__( 'Test Types', 'your-textdomain' ),
            'singular_name'              => esc_html__( 'Test Type', 'your-textdomain' ),
            'menu_name'                  => esc_html__( 'Test Types', 'your-textdomain' ),
            'search_items'               => esc_html__( 'Search Test Types', 'your-textdomain' ),
            'popular_items'              => esc_html__( 'Popular Test Types', 'your-textdomain' ),
            'all_items'                  => esc_html__( 'All Test Types', 'your-textdomain' ),
            'parent_item'                => esc_html__( 'Parent Test Type', 'your-textdomain' ),
            'parent_item_colon'          => esc_html__( 'Parent Test Type', 'your-textdomain' ),
            'edit_item'                  => esc_html__( 'Edit Test Type', 'your-textdomain' ),
            'view_item'                  => esc_html__( 'View Test Type', 'your-textdomain' ),
            'update_item'                => esc_html__( 'Update Test Type', 'your-textdomain' ),
            'add_new_item'               => esc_html__( 'Add new test type', 'your-textdomain' ),
            'new_item_name'              => esc_html__( 'New test type name', 'your-textdomain' ),
            'separate_items_with_commas' => esc_html__( 'Separate test types with commas', 'your-textdomain' ),
            'add_or_remove_items'        => esc_html__( 'Add or remove test types', 'your-textdomain' ),
            'choose_from_most_used'      => esc_html__( 'Choose most used test types', 'your-textdomain' ),
            'not_found'                  => esc_html__( 'No test types found', 'your-textdomain' ),
            'no_terms'                   => esc_html__( 'No test types found', 'your-textdomain' ),
            'items_list_navigation'      => esc_html__( 'Test types list pagination', 'your-textdomain' ),
            'items_list'                 => esc_html__( 'Test Types list', 'your-textdomain' ),
            'most_used'                  => esc_html__( 'Most Used', 'your-textdomain' ),
            'back_to_items'              => esc_html__( 'Back to test types', 'your-textdomain' ),
            'text_domain'                => esc_html__( 'your-textdomain', 'your-textdomain' ),
        ];
        $args = [
            'label'              => esc_html__( 'Test Types', 'your-textdomain' ),
            'labels'             => $labels,
            'description'        => '',
            'public'             => true,
            'publicly_queryable' => true,
            'hierarchical'       => false,
            'show_ui'            => true,
            'show_in_menu'       => true,
            'show_in_nav_menus'  => true,
            'meta_box_cb'        => true,
            'show_in_rest'       => true,
            'show_tagcloud'      => true,
            'show_in_quick_edit' => true,
            'show_admin_column'  => false,
            'query_var'          => true,
            'sort'               => false,
            'rest_base'          => '',
            'rewrite'            => [
                'with_front'   => false,
                'hierarchical' => false,
            ],
        ];
        register_taxonomy( 'test-type', ['test-pt'], $args );
    }

    This is the block:

    add_filter( 'rwmb_meta_boxes', 'your_prefix_register_meta_boxes' );
    
    function your_prefix_register_meta_boxes( $meta_boxes ) {
        $prefix = '';
    
        $meta_boxes[] = [
            'title'    => esc_html__( 'Test BLCK', 'text-domain' ),
            'id'       => 'test-blck',
            'fields'   => [
                [
                    'id'   => $prefix . 'text_hdsmywqrchf',
                    'type' => 'text',
                    'name' => esc_html__( 'Text Field Test BLCK', 'text-domain' ),
                ],
                [
                    'id'         => $prefix . 'taxonomy_rjokxm5oyo9',
                    'type'       => 'taxonomy',
                    'name'       => esc_html__( 'Taxonomy Field', 'text-domain' ),
                    'taxonomy'   => 'test-type',
                    'field_type' => 'select',
                ],
            ],
            'category' => 'layout',
            'icon'     => 'admin-appearance',
            'type'     => 'block',
            'mode'     => 'edit',
        ];
    
        return $meta_boxes;
    }

    And this is the problem:
    https://share.getcloudapp.com/4guOj2m5

    thanks for your support.

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

    Hi,

    The field taxonomy doesn’t store any terms in the post meta. Instead, it sets post terms. Just like a replacement of Category or Tag meta box of WordPress so it does not work with Group or Block. If you want to save the taxonomy as the post meta or Block content, please use the field taxonomy_advanced.

    For more information, please follow these documentations.
    https://docs.metabox.io/fields/taxonomy-advanced/
    https://docs.metabox.io/fields/taxonomy/#data

    #23429
    DANIEL FITIPALDO R.
    Participant

    Excelent. I changed to taxonomy_advanced and worked fine.
    thank you! you can close the ticket as resolved.

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