• Resolved dtszero

    (@dtszero)


    Hi!

    I have some issues with the taxonomy multicheck and taxonomy radio fields. The cmb2 display the values on the back also they’re remember the choices on the fields. But they’re not create the custom fields or any other data to display in the front.

    I look on the output of the get_post_meta() function but always it’s empty.

    Register code of Metabox

    add_action('cmb2_admin_init', 'metaboxes_manga_c2' );
    function metaboxes_manga_c2() {
      $prefix = 'am_fields_manga_';
    
      // Metabox
      $metabox_manga = new_cmb2_box(array(
        'id'        => $prefix . 'metabox',
        'title'     => __('Mangas', 'cmb2'),
        'object_types' => array('manga')
      ) );
      # Metabox
    

    Field code

    $web_hosts = $metabox_manga->add_field(array(
        'name'           => __('Servidores de descarga', 'cmb2'),
      	'id'             => $prefix . 'web_hosts',
      	'taxonomy'       => 'dd_servers', // Taxonomy Slug
      	'type'           => 'taxonomy_multicheck_inline',
        'select_all_button' => false,
      	'text'           => array('no_terms_text' => 'No se han encontrado datos...'),
        'remove_default' => 'true' // Removes the default metabox
      ) );
    
    $format = $metabox_manga->add_field(array(
        'name'    => __('Formato', 'cmb2'),
      	'id'       => $prefix . 'format',
        'taxonomy'    => 'category', // Enter Taxonomy Slug
      	'type'    => 'taxonomy_radio_inline',
        'text'    => array( 'no_terms_text' => 'No hay categorías que mostrar.' ),
      	'remove_default' => 'true'
      ) );
    

    Register taxonomy code

    function am_dd_servers_taxonomy(){
      $labels = array(
      'name'              => _x( 'Descargar Anime', 'taxonomy general name' ),
      'singular_name'     => _x( 'Servidor de Descarga', 'taxonomy singular name' ),
      'search_items'      => __( 'Buscar Servidores de Descarga' ),
      'all_items'         => __( 'Todos los Servidores de Descarga' ),
      'parent_item'       => __( 'Superior' ),
      'parent_item_colon' => __( 'Superior' ),
      'edit_item'         => __( 'Editar Servidor de Descarga' ),
      'update_item'       => __( 'Actualizar Servidor de Descarga' ),
      'add_new_item'      => __( 'Agregar Servidor de Descarga' ),
      'new_item_name'     => __( 'Nuevo Servidor de Descarga' ),
      'menu_name'         => __( 'Servidores de Descarga' ),
      );
    
      $args = array(
      'hierarchical'      => true, //like post or pages
      'labels'            => $labels, //add the labels
      'show_ui'           => true, // add the default UI to this
      'show_admin_column' => false, //Show the Taxonomy in the admin menu
      'query_var'         => true, //enable or desable the default variable
      'rewrite' => array( 'slug' => 'descargar-anime' ), // rewrite default url
      );
    
      register_taxonomy(
        'dd_servers',
        array( 'anime', 'manga' ), // Show in...
        $args
      );
    }
    add_action ( "init", "am_dd_servers_taxonomy" );
    

    Function to output on frontend

    $web_hosts = get_post_meta( get_the_ID(), 'web_hosts', true);
    OR
    $web_hosts = get_the_term_list( get_the_ID(), 'web_hosts', '', ', ' );
    

    This is the image of the avalible custom fields, and I don’t see the taxonomy’s

    View post on imgur.com

Viewing 1 replies (of 1 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Some quick notes for you:

    Any of the field types that start with “taxonomy_” are meant to replace the default metaboxes for the terms. They do not set anything as post meta, they update the associated terms with the posts. For those, you’ll want to use term/taxonomy based WordPress functions to fetch that info.

    This line is your closest to what you need, but it’s not there yet:

    $web_hosts = get_the_term_list( get_the_ID(), 'web_hosts', '', ', ' );
    

    “web_hosts”, based on what I can see in the code above, is not a valid taxonomy, you’re going to want to use either dd_servers or category for that line.

    Hopefully this gets you closer to what you need here.

Viewing 1 replies (of 1 total)
  • The topic ‘Taxonomy multicheck/radio doesn’t work on output’ is closed to new replies.