-1

I am working on project of having custom product list with having multi-level categories of products, if user clicks on 1 category/taxonomy it will go to its sub-category & then it will show all the list of its posts (CPT). I've created custom post type of 'Our Products' This is the CPT code I've created:

// Register Custom Post Type Our Product
function create_ourproduct_cpt() {
$labels = array(
    'name' => _x( 'Our Products', 'Post Type General Name', 'our-products' ),
    'singular_name' => _x( 'Our Product', 'Post Type Singular Name', 'our-products' ),
    'menu_name' => _x( 'Our Products', 'Admin Menu text', 'our-products' ),
    'name_admin_bar' => _x( 'Our Product', 'Add New on Toolbar', 'our-products' ),
    'archives' => __( 'Our Product Archives', 'our-products' ),
    'attributes' => __( 'Our Product Attributes', 'our-products' ),
    'parent_item_colon' => __( 'Parent Our Product:', 'our-products' ),
    'all_items' => __( 'All Our Products', 'our-products' ),
    'add_new_item' => __( 'Add New Our Product', 'our-products' ),
    'add_new' => __( 'Add New', 'our-products' ),
    'new_item' => __( 'New Our Product', 'our-products' ),
    'edit_item' => __( 'Edit Our Product', 'our-products' ),
    'update_item' => __( 'Update Our Product', 'our-products' ),
    'view_item' => __( 'View Our Product', 'our-products' ),
    'view_items' => __( 'View Our Products', 'our-products' ),
    'search_items' => __( 'Search Our Product', 'our-products' ),
    'not_found' => __( 'Not found', 'our-products' ),
    'not_found_in_trash' => __( 'Not found in Trash', 'our-products' ),
    'featured_image' => __( 'Featured Image', 'our-products' ),
    'set_featured_image' => __( 'Set featured image', 'our-products' ),
    'remove_featured_image' => __( 'Remove featured image', 'our-products' ),
    'use_featured_image' => __( 'Use as featured image', 'our-products' ),
    'insert_into_item' => __( 'Insert into Our Product', 'our-products' ),
    'uploaded_to_this_item' => __( 'Uploaded to this Our Product', 'our-products' ),
    'items_list' => __( 'Our Products list', 'our-products' ),
    'items_list_navigation' => __( 'Our Products list navigation', 'our-products' ),
    'filter_items_list' => __( 'Filter Our Products list', 'our-products' ),
);
$args = array(
    'label' => __( 'Our Product', 'our-products' ),
    'description' => __( 'Our Products Section', 'our-products' ),
    'labels' => $labels,
    'menu_icon' => 'dashicons-grid-view',
    'supports' => array('title', 'editor', 'excerpt', 'thumbnail', 'revisions', 'author', 'comments', 'trackbacks', 'page-attributes', 'post-formats', 'custom-fields'),
    'taxonomies' => array(),
            //'taxonomies' => array('categories'),
    'public' => true,
    'show_ui' => true,
    'show_in_menu' => true,
    'menu_position' => 5,
    'show_in_admin_bar' => true,
    'show_in_nav_menus' => true,
    'can_export' => true,
    'has_archive' => true,
    'hierarchical' => true,
    'exclude_from_search' => false,
    'show_in_rest' => true,
    'publicly_queryable' => true,
    'capability_type' => 'post',
);
register_post_type( 'ourproduct', $args );
}
add_action( 'init', 'create_ourproduct_cpt', 0 );

And below is also the code for product CPT taxonomy:

//our product category taxonomy
function tr_create_my_taxonomy() {
    register_taxonomy(
        'ourproduct-category',
        'ourproduct',
        array(
            'label' => __( 'Prod Category' ),
            'rewrite' => array( 'slug' => 'prod-category' ),
            'hierarchical' => true,
        )
    );
}
add_action( 'init', 'tr_create_my_taxonomy' );

Below is the reference site you can check: https://www.nasseriequipment.com/products-boom-loader-forklift-17.html

Please let me know how we can get the list of categories with its multi-level hierarchy

  • Yea I've checked & tried most of the things but I didn't get the solution what I want – Naseer Ahmed Arshad Aug 27 '19 at 09:07
  • Show / explain what you tried. And be a bit more specific on what exact result you actually want to begin with. – misorude Aug 27 '19 at 09:11
  • Basically I am not a developer I am Web Designer, I worked on PSD to HTML/CSS & jQuery, I've designed some WordPress themes but the problem is much knowledge of PHP & WordPress development, I've search on google, got some codes from wordpress & other sources as well I've tried them but those are not working some are: https://developer.wordpress.org/reference/functions/get_terms/ https://wordpress.org/plugins/custom-post-type-widgets/#description – Naseer Ahmed Arshad Aug 27 '19 at 09:22
  • Hope you understand – Naseer Ahmed Arshad Aug 27 '19 at 09:23
  • Suggest you start by having a look at https://developer.wordpress.org/reference/functions/wp_list_categories/ – misorude Aug 27 '19 at 09:24
  • '; foreach ( $terms as $term ) { echo '
  • ' . $term->name . '
  • '; } echo ''; } ?> this code recently I've tried but its showing only the list of categories without link – Naseer Ahmed Arshad Aug 27 '19 at 09:33
  • Well where do you expect any links to come from, if you only create a UL/LI structure? Put a link inside the LI then … – misorude Aug 27 '19 at 09:38
  • Yea I've added the link but its going directly to product not on its sub category – Naseer Ahmed Arshad Aug 27 '19 at 09:46
  • No idea _what_ you added, so impossible to tell whether it’s the right thing or not. – misorude Aug 27 '19 at 09:47