Custom Taxonomy within another Custom Taxonomy in WordPress

1

I need to create the following hierarchy within the WordPress admin:

Category - > Product Line - > Product

A product belongs to a line that in turn belongs to a category.

I thought about creating a Custom Taxonomy for Categories, one for Lines. Populate them with the necessary data.

What I need to know if it is possible is when to create a product (post), if there is any way to pull into a select the created categories and the lines created to insert into the product.

Is there a possibility?

Thank you.

    
asked by anonymous 07.04.2016 / 00:58

1 answer

0

You can make the products as custom posts and create the taxonomies and terms appropriate for them.

EX:

Category - > subcategory - > post

Category - > product line - > product

The two running in parallel and without having to change anything at the time of registering the product, since it will respond to their own categories and terms.

To create the custom you need to put this in functions.php:

add_action('init', 'type_post_produto');
function type_post_produto() { 
            $labels = array(
                'name' => _x('Produto', 'post type general name'),
                'singular_name' => _x('Produto', 'post type singular name'),
                'add_new' => _x('Adicionar Novo Produto', 'Novo Produto'),
                'add_new_item' => __('Novo Produto'),
                'edit_item' => __('Editar Produto'),
                'new_item' => __('Novo Produto'),
                'view_item' => __('Ver Produto'),
                'search_items' => __('Procurar Produto'),
                'not_found' =>  __('Nenhum registro encontrado'),
                'not_found_in_trash' => __('Nenhum registro encontrado na lixeira'),
                'parent_item_colon' => '',
                'menu_name' => 'Produtos'
            );

            $args = array(
                'labels' => $labels,
                'public' => true,
                'public_queryable' => true,
                'show_ui' => true,      
                'query_var' => true,
                'taxonomies' => array( 'Categoria' ),
                'rewrite' => array('slug' => 'produto'),
                'capability_type' => 'post',
                'has_archive' => true,
                'hierarchical' => false,
                'menu_position' => null, 
                'supports' => array('title', 'editor', 'thumbnail', 'revisions'),
            );

        register_post_type( 'produtos' , $args );
        flush_rewrite_rules();
        }

With this you will only need to create product category hierarchies and create custom loops to retrieve the "products."

    
27.04.2016 / 15:35