Create taxonomy and custom post type
function taxonomy_init() {
// create a new taxonomy
register_taxonomy(
'product_category',
'product_post',
array(
'label' => __( 'Product categories' ),
'singular_label' => 'Product Category',
'hierarchical' => true,
'query_var' => true,
'rewrite' => array(
'slug' => 'product-category'
),
)
);
$args = array(
'labels' => array(
'name' => _x('Products', 'post type general name'),
'singular_name' => _x('Product', 'post type singular name')
),
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'query_var' => true,
'capability_type' => 'post',
'hierarchical' => false,
'menu_position' => null,
'supports' => array('title', 'editor', 'thumbnail', 'page-attributes'),
'rewrite' => array(
'slug' => 'product',
'with_front' => false
),
'has_archive' => 'products'
);
register_post_type('product_post', $args);
flush_rewrite_rules();
}
add_action( 'init', 'taxonomy_init');
Custom Taxonomy Tree view
<?php
//Walker function
function custom_taxonomy_walker($taxonomy, $parent = 0)
{
$terms = get_terms($taxonomy, array('parent' => $parent, 'hide_empty' => false));
//If there are terms, start displaying
if(count($terms) > 0)
{
//Displaying as a list
$out = "<ul>";
//Cycle though the terms
foreach ($terms as $term)
{
//Secret sauce. Function calls itself to display child elements, if any
$out .="<li>" . $term->name . custom_taxonomy_walker($taxonomy, $term->term_id) . "</li>";
}
$out .= "</ul>";
return $out;
}
return;
}
//Example
echo custom_taxonomy_walker('category');
?>
<?php
$args = array(
'taxonomy' => 'product-type',
'hierarchical' => true,
'title_li' => '',
'hide_empty' => false
);
?>
<ul>
<?php wp_list_categories( $args ); ?>
</ul>
https://wordpress.org/plugins/advanced-custom-fields-categories/
https://wordpress.org/plugins/custom-taxonomy-order-ne/screenshots/