I’m using wordpress metabox plugin – CMB2 (version CMB2-2.2.4). I want to make a custom field of 'type' => 'taxonomy_radio' for all pages.

But the problem is that after changing and updating the selected value (category) does not change in admin panel. And when I output this data in my theme no output shows. But, It works very fine when I use 'type' => 'radio'.

I don’t understand where is the problem. Here is my code.

In functions.php

$prefix = 'yourprefix_demo_';

$cmb_demo = new_cmb2_box( array(
    'id'            => $prefix . 'metabox',
    'title'         => esc_html__( 'Test Metabox', 'cmb2' ),
    'object_types'  => array('page'), // Post type

) );

$cmb_demo->add_field( array(
    'name'     => esc_html__( 'Test Taxonomy Radio', 'cmb2' ),
    'desc'     => esc_html__( 'field description (optional)', 'cmb2' ),
    'id'       => $prefix . 'text_taxonomy_radio',
    'type'     => 'taxonomy_radio',
    'taxonomy' => 'category', // Taxonomy Slug
) );

In front Pages:

<?php
   $prefix = 'yourprefix_demo_';
   echo get_post_meta(get_the_ID(), $prefix.'text_taxonomy_radio', true);
?>

Thank in advance 🙂

Read more here: CMB2 not working properly


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: