There is already a function in WordPress doing that: wp_terms_checklist()
. It is used in the metabox for hierarchical taxonomies in the post editor. Maybe you can reuse that?
The following is untested, see it just as a guide please, not as a complete solution:
// File where "wp_terms_checklist()" is declared
require_once ABSPATH . 'wp-admin/includes/template.php';
// Output will be printed immediately
wp_terms_checklist(
0, // post ID
array (
'descendants_and_self' => 0,
'selected_cats' => FALSE,
'popular_cats' => FALSE,
'walker' => NULL,
'taxonomy' => 'wpsc-variation',
'checked_ontop' => FALSE
)
);
Related Posts:
- Return array of categories to php function
- Listing all posts from current category on page
- Display WooCommerce product categories in a 4 columns custom menu [closed]
- Show post only if match all categories
- Dropdown category filter
- How to use an array of categories as a dropdown?
- Create menu locations for each category in wordpress
- Use premade array as categories in wp_query?
- Array: What is this value based on?
- How to get an array with all categories and corresponding names?
- Link To Child Category For A Post
- List a maximum of ‘x’ product categories with qty of ‘y’ in each column
- Need to echo category id in multi-dimensional array
- Getting Category Children
- I need to exclude from a query a category and a few custom taxonomies
- Cant get unique_array() work on get_the_category() foreach loop
- Matching usermeta at registration to categories of content
- How to change category id on get_posts array
- How to define category ID in an array?
- Order Categories by Character Count
- how do I exclude a category foreach
- List all subcategories from category
- Get the children of the parent category
- How to remove the term “category” from category pagination?
- Force WordPress to Show Pages Instead of Category
- How do I get the category URL from get_the_category?
- How to Set an Individual Homepage for Each User?
- Is there a way to remove categories in bulk?
- Is it possible to put next and previous category links?
- Custom category template pagination problem
- Getting category before saving post
- How do I change the sql query for wp_get_archive()
- New categories are now going to 404s
- How to put enctype=”multipart/form-data” in categories form?
- “Reversable” and “Re-useable” Subcategories (or other taxonomic structure)
- What is the advantage of using header-catname.php over is_category(‘catname’);?
- Insert Into Sub-child Menu
- Search Posts / Pages with multiple options?
- Category location styling
- Get Tags specific to Category using WooCommerce plugin
- Giving wp_list_categories the class of the category
- Category archive rewrite rule to include category/subcategory?
- How can I automatically display a visual archive of subcategory posts [and thumbnails] separate from Parent category?
- The default code for “posts_nav_link” on category.php isn’t working
- How to organize custom categories for filtering and selecting
- Woocommerce custom category pages
- Custom sub taxonomy order by
- Hide uncategorized when no category set
- Refine/Filter the Search Results by Category
- Have multiple category queries from the URL been fixed yet?
- Why is it so hard to show the URL of the current category and how to do it?
- How to get Next/previous_post_link to go through articles in top parent category
- Conditional loop for category
- How to make the ‘delete’ button inactive on some categories?
- Notice: Trying to get property of non-object in : custom fields category
- Thumbnail for categories / taxonomies plugin?
- Pagination for query_posts();
- echo get_post_meta of all post in a category to fill up a select field
- How to Link to Most Recent Custom Post of Same Term
- WP REST API not retrieving all categories
- Notice: Undefined variable: category_id
- Change RSS format for specific categories
- List post only under the category, exclude child category content
- Detect category choice for posts with multiple categories
- wp_insert_link not working
- Different size video display for category page (smaller) & detail page (larger)
- Adding tinymce to Custom Field boxes on Category edit page
- wp_list_categories : how do I sort by ID when IDs are not sequential
- Showing different posts on category pages
- add current-cat class to single post page
- How to exclude certain categories showing in Gutenberg?
- Problem with pagination block in Gutenberg
- How to redirect to category page if page does not exists?
- Sort categories by custom field in WordPress admin
- Remove “Category:” from Post meta
- Related to genre and category
- Get permalink to latest post in category
- How to load terms of a custom taxonomy of a product in woocommerce cart page
- restrict category to only logged in User
- Category and tag urls return 404 error
- Dynamically creating content on custom URL without getting 404
- Removin /page/2 from pagination
- get parent_category class in loop
- Group Posts by First Letter of Title categories
- Display all of a post’s categories except the current category
- Alphabetize all but one category
- How to display only category of blog without custom code?
- How to create a category or tag available exclusively to the admins and not to the users?
- Printing direct descendants of a category with WP_Query
- wordpress category.php query for featured news item, broken pagination and repeating posts
- Form Value of drop down category + Translation of ‘show option none’
- Echo class depending on Parent category
- Query pages by category
- List all authors by matching custom meta data on a category page
- Page view: Sorted by categories
- Anyway to hide a Category in the Categories section when adding/editing a post in WP Admin?
- How to display posts by author in a separate page, other than author.php?
- One color to category link depending on category ID
- Show subcategories and hide posts or show posts if not exists subcategories
- Restricted category in Woocommerce [closed]