WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Taxonomy Category And Subcategory (2 posts)

  1. kuroski
    Member
    Posted 9 months ago #

    Hello guys, I'm not very good at English, but I'm gonna try.

    I'm in the following case:

    - I need to create a panel session to register products with their respective categories and subcategories.

    EX:
    Category:

    - Vase / Chair / T-shirt

    SubCategory:
    - Vase
    -- Clay Pots (Pot belongs to category Vase)
    -- Vessels Cement (belongs to category Vase)

    - Chair
    - Reclining Chairs (Chair belongs to category Chair)
    - Padded Chairs (Chair belongs to category Chair)

    - T-shirt
    - Regatta (belongs to category T-shirt)
    - Polo (belongs to category T-shirt)

    I need to create this structure to register a product.

    EX:

    Product: ProdX
    - Category: T-shirt
    - Subcategory: Polo

    Well, I do not know how I do the record straight, I only have part of the product / category ready.

    add_action('init', 'product_register');
    if (!function_exists('product_register')) {
        function product_register() {
            $labels = array(
                'name' => __('Product', 'tkwave'),
                'singular_name' => __('Product', 'tkwave'),
                'add_new' => __('Add New', 'tkwave'),
                'add_new_item' => __('Add New Product', 'tkwave'),
                'edit_item' => __('Edit Product', 'tkwave'),
                'new_item' => __('New Product', 'tkwave'),
                'all_items' => __('All Products', 'tkwave'),
                'view_item' => __('View Product', 'tkwave'),
                'search_items' => __('Search Products', 'tkwave'),
                'not_found' =>  __('No Producct found', 'tkwave'),
                'not_found_in_trash' => __('No Product found in Trash', 'tkwave'),
                'menu_name' => __('Products', 'tkwave')
            );
            $args = array(
                'labels' => $labels,
                'public' => true,
                '_builtin' => false,
                'capability_type' => 'post',
                'menu_icon' => THEME_DIR . '/framework/assets/images/product.png',
                'hierarchical' => false,
                'rewrite' => array( 'slug' => 'product'),
                'supports' => array('title', 'editor', 'thumbnail')
            );
            register_post_type('product', $args);
            flush_rewrite_rules();
        }
    }
    
    register_taxonomy("products", array("product"), array("hierarchical" => true, "label" => __("Categories", "tkwave"), "singular_label" => __("Product Categorie", "tkwave"), "rewrite" => true));
  2. kuroski
    Member
    Posted 9 months ago #

    Good night guys.

    I ended up finding a solution to my question, it was not ideal (because I wanted to create a field of subcategories) but the result is the same.

    Basically when you create the post type product and taxonomy categories, the panel category has a select input that you select who the father is.

    So basically I register a category.
    And to register a subcategory, I just had to select the parent (father) category.

    And to limit the number of categories of the products, I downloaded the following plugin

    Radio Buttons for taxonomies:
    http://www.kathyisawesome.com/441/radio-buttons-for-taxonomies/

    In it I can select the taxonomy that I want to limit to 1 category (or sub) selected

Reply

You must log in to post.

About this Topic