Custom taxonomy in WordPress
-
Hola!
I faced a very big challenge.
more than a week that I would like to create a group of category to regroup certain hotels by their different city.Here is an example of my custom taxonomy will be:
.Hotel
– city 1
– Hotel 1
– Hotel 2
– Hotel 3– city 2
– Hotel 1
– Hotel 2
– Hotel 3
ect …After my Investigations, I was able to realize this piece of code.
<?php /* Description: METABOXES ACUERDO Licence URI: https://www.gnu.org/licenses/gpl-2.0.html */ function crear_post_type_acuerdos() { $labels = array( 'name' => _x( 'Acuerdos', 'maec' ), 'singular_name' => _x( 'acuerdo', 'maec' ), 'add_new' => __( 'Add New','maec'), 'add_new_item' => __( 'Add New','maec'), 'edit_item' => __( 'Edit acuerdo','maec' ), 'new_item' => __( 'Add New','maec' ), 'all_items' => __( 'All acuerdos','maec' ), 'view_item' => __( 'Ver acuerdo','maec'), 'search_items' => __( 'Search acuerdo','maec'), 'not_found' => __( 'Not Found!','maec' ), 'not_found_in_trash' => __( 'Not Found en la papelera','maec' ), 'parent_item_colon' => '', 'menu_name' => __('ACUERDOS','maec') ); $args = array( 'labels' => $labels, 'public' => true, 'publicly_queryable' => true, 'show_ui' => true, 'show_in_menu' => true, 'query_var' => true, 'rewrite' => true, 'has_archive' => true, 'capability_type' => 'post', 'menu_icon' => 'dashicons-welcome-learn-more', 'can_export' => true, 'hierarchical' => false, 'menu_position' => 18, 'supports' => array('title', 'thumbnail', 'revisions') ); //registrar post type register_post_type( 'acuerdos', $args); } add_action('init', 'crear_post_type_acuerdos', 0); add_action( 'cmb2_admin_init', 'acuerdos_repeater_metaboxes' ); /** * Define the metabox and field configurations. */ function acuerdos_repeater_metaboxes() { /** * Initiate the metabox */ $cmb = new_cmb2_box( array( 'id' => 'repeater_demo', // Belgrove Bouncing Castles 'title' => 'Repeater Demo', 'object_types' => array( 'acuerdos', ), // Post type 'context' => 'normal', 'priority' => 'high', 'show_names' => true, // Show field names on the left ) ); $blog_group_id = $cmb->add_field( array( 'id' => 'blog_group', 'type' => 'group', 'repeatable' => true, 'options' => array( 'group_title' => 'Post {#}', 'add_button' => 'Add Another Post', 'remove_button' => 'Remove Post', 'closed' => true, // Repeater fields closed by default - neat & compact. 'sortable' => true, // Allow changing the order of repeated groups. ), ) ); $cmb->add_group_field( $blog_group_id, array( 'name' => 'Post Title', 'desc' => 'Enter the post title for the link text.', 'id' => 'title', 'type' => 'text', ) ); $cmb->add_group_field( $blog_group_id, array( 'name' => 'Description', 'desc' => 'Enter the post Description for the link text.', 'id' => 'description', 'type' => 'textarea_small', ) ); } function taxonomia_categorie_acuerdos() { $labels = array( 'name' => _x('categorie acuerdos', 'taxonomy general name'), 'singular_name' => _x('categorie acuerdos', 'taxonomy singular name'), 'search_items' => __('Search categorie acuerdos'), 'all_items' => __('All categorie acuerdos'), 'parent_item' => __('categorie acuerdos Padre'), 'parent_item_colon' => __('categorie acuerdos Padre:'), 'edit_item' => __('Edit categorie acuerdos'), 'update_item' => __('Update categorie acuerdos'), 'add_new_item' => __('Add New categorie acuerdos'), 'new_item_name' => __('New categorie acuerdos'), 'menu_name' => __('categorie acuerdos'), ); $args = array( 'hierarchical' => true, 'labels' => $labels, 'show_ui' => true, 'show_admin_column' => true, 'query_var' => true, 'rewrite' => array('slug' => 'categorie-acuerdos') ); register_taxonomy('categorie-acuerdos', array('acuerdos'), $args); } add_action('init', 'taxonomia_categorie_acuerdos');I have a huge dificulty to view.
My question is as follows:
– how to proceed to visualize the different categories and a single to read the content.In the tutorials algunos hablan of the página archive.php o of taxonomy, sincerely I am lost.
A help will come to me very well to finish my project.thank you
The topic ‘Custom taxonomy in WordPress’ is closed to new replies.