No me guarda una taxonomía personalizada en un CPT
-
Buenos días. Tengo un CTP con una taxonomía personalizada. En el post en cuestión, tengo creado un metabox para elegir la taxonomía, y las distintas taxonomías se eligen mediante un radio button. Sin embargo, no me guarda el valor elegido, cosa que sí hace desde la Edición Rápida (por este motivo, sé que el problema está en la metabox). Me gustaría mostrar una metabox en el que elegir la categoría, pero una única. Este es el código que tengo ahora mismo:
/* CAMBIO A RADIO BUTTON LA TAXONOMÍA SISTEMA */ //add_action( 'admin_menu', 'myprefix_remove_meta_box'); function myprefix_remove_meta_box(){ remove_meta_box('sistemasdiv', 'cliente-satisfecho', 'normal'); } //Add new taxonomy meta box add_action( 'add_meta_boxes', 'myprefix_add_meta_box'); function myprefix_add_meta_box() { add_meta_box( 'sistema_id', 'Sistemas','sistema_metabox','cliente-satisfecho' ,'side','core'); } //Callback to set up the metabox function sistema_metabox( $post ) { //Get taxonomy and terms $taxonomy = 'sistemas'; //Set up the taxonomy object and get terms $tax = get_taxonomy($taxonomy); $terms = get_terms($taxonomy,array('hide_empty' => 0)); //Name of the form $name = 'tax_input[' . $taxonomy . ']'; //Get current and popular terms $popular = get_terms( $taxonomy, array( 'orderby' => 'count', 'order' => 'DESC', 'number' => 10, 'hierarchical' => false ) ); $postterms = get_the_terms( $post->ID,$taxonomy ); $current = ($postterms ? array_pop($postterms) : false); $current = ($current ? $current->term_id : 0); ?> <div id="taxonomy-<?php echo $taxonomy; ?>" class="categorydiv"> <!-- Display tabs--> <ul id="<?php echo $taxonomy; ?>-tabs" class="category-tabs"> <li class="tabs"><a href="#<?php echo $taxonomy; ?>-all" tabindex="3"><?php echo $tax->labels->all_items; ?></a></li> <li class="hide-if-no-js"><a href="#<?php echo $taxonomy; ?>-pop" tabindex="3"><?php _e( 'Más usados' ); ?></a></li> </ul> <!-- Display taxonomy terms --> <div id="<?php echo $taxonomy; ?>-all" class="tabs-panel"> <ul id="<?php echo $taxonomy; ?>checklist" class="list:<?php echo $taxonomy?> categorychecklist form-no-clear"> <?php foreach($terms as $term){ $id = $taxonomy.'-'.$term->term_id; echo "<li id='$id'><label class='selectit'>"; echo "<input type='radio' id='in-$id' name='{$name}'".checked($current,$term->term_id,false)."value='$term->term_id' />$term->name<br />"; echo "</label></li>"; }?> </ul> </div> <!-- Display popular taxonomy terms --> <div id="<?php echo $taxonomy; ?>-pop" class="tabs-panel" style="display: none;"> <ul id="<?php echo $taxonomy; ?>checklist-pop" class="categorychecklist form-no-clear" > <?php foreach($popular as $term){ $id = 'popular-'.$taxonomy.'-'.$term->term_id; echo "<li id='$id'><label class='selectit'>"; echo "<input type='radio' id='in-$id'".checked($current,$term->term_id,false)."value='$term->term_id' />$term->name<br />"; echo "</label></li>"; }?> </ul> </div> </div> <?php } add_action('admin_enqueue_scripts','myprefix_radiotax_javascript'); function myprefix_radiotax_javascript(){ wp_register_script( 'radiotax', get_template_directory_uri() . '/js/radiotax.js', array('jquery'), null, true ); // We specify true here to tell WordPress this script needs to be loaded in the footer wp_enqueue_script( 'radiotax' ); }
Gracias
Por cierto, tengo habilitado Gutemberg en el CPT. No sé si será eso. Además, tampoco me aparece una metabox para la etiquetas. ¿Cómo podría crear una metabox para las etiquetas?
La página con la que necesito ayuda: [accede para ver el enlace]
- El debate ‘No me guarda una taxonomía personalizada en un CPT’ está cerrado a nuevas respuestas.