To fix this you will need to pass in multiple terms rather than a single term
so instead of:
$_POST['main_cat']
Use:
array($_POST['main_cat'],$_POST['sub_cat'])
You shouldn’t need to save main_cat though. Assigning sub_cat should imply it’s also in subcat’s parent term
Related Posts:
- How to retain the values from dropdown category lists after wrong form submission?
- Additional form options based on category selected not working
- Exclude category from drop down list form
- How do I create a way for users to assign categories to a post from the frontend?
- Dropdown with category selection
- List custom post types in dropdown
- How to Make a Categories Meta Box with Hierarchical Checkboxes on Frontend?
- Get id of category from drop down menu
- How to add HTML5 ‘required’ attribute to wp_dropdown_categories() without JavaScripts?
- exclude category from WordPress Form function
- Help with multiple dropdown tags search
- How to use wp_category_checklist()?
- wp_dropdown_categories and custom taxonomy + custom post type
- How to provide value for ‘selected’ on wp_dropdown_categories() for ‘multiple’ options
- How do I create a way for users to assign categories to a post from the frontend of the website?
- wp_dropdown_categories() scripts working erratically on sidebar
- How to use an array of categories as a dropdown?
- wp_update_post is not updating category
- How do I display only two categories Instead of displaying all categories
- Dropdown Categories used in form shows no results when all is selected
- Trying to get variables in hacked category dropdown
- wp_list_categories walker without links on categories that have subcategories (to make a nested dropdown menu)
- Filter posts by categories ajax is showing nothing
- WordPress Customizer: Dropdown with Category output
- Filter By Category Dropdown List With Custom Taxonomies
- A dropdown with checklist
- Search form options group categories
- Redirect depending on category chosen
- Wp Dropdown Category Not Show Current As Title
- wp_dropdown_categories initial value
- Create a Category with a front-end post
- Update custom category fields front-end
- Why are my newly added categories not showing up when creating a post?
- Trying to get categories and sub-category listing
- front end add category to new post
- Get_term_meta() always returns false
- Woocommerce Category Sort Dropdown
- How to add custom option to wp_dropdown_categories?
- Default URL for category dropdown select option
- custom browse by
- Getting Custom post category from Form
- wp_category_checklist won’t show up for non-admin users
- How to Query the Top 5 Posts of a specific category?
- Get category fixed in dropdown browse categories
- Categories dropdown with all values selected using wp_dropdown_categories
- Front end page submission form does not attach custom post type
- add custom option to get_categories dropdown
- Taxonomy for custom post type not found
- Ajax call activate after submit in edit-tags.php page
- Form Value of drop down category + Translation of ‘show option none’
- Categories as selectable links on submission form
- Fetch Post Category
- Bulk Change WordPress category Slug
- Hiding by default posts in given category except for some cases
- Post url rewriting for posts with certain category
- How to get the term id inside the start lvl method of category walker?
- How to use categories, sub-categories and customize navigation view
- Hide empty category on woocommerce
- Media Library Category Exclude Tree
- Media Library Categories
- Hide post category name wherever it might be mentioned
- Multiple if statements with else for get_the_category [closed]
- When category name and title are the same … WP will select archive.php instead of single.php
- Exclude category from WP_Query args not working
- How to apply wordpress ‘with_front’ = false for categories?
- Custom Category Archive Pages
- Add subcategories posts to the counts column at the admin’s categories list
- Re-coding category-template.php to go to custom URL
- Category removal – Portfolio Category:
- Assign a class to first element in category in loop
- Balance Tags to the_content Words Length
- How to create template for children category?
- Custom dropdown search form that allows users to select option B based from Option 1
- PHP drop down menu for my get_category child of
- Filter custom taxonomy posts via AJAX
- set a parent category in a product woocommerce
- restrict category to only logged in User
- “Next posts” of a category do not call category.php
- Category and tag urls return 404 error
- No results found for second level category
- Categories Help and video uploads
- get_the_category vs wp_get_post_categories
- Displaying Category in sidebar post widget but not in the loop on home
- How to display products with multiple conditions, product_id and category_id
- Create duplicate category page with content variations
- Why use hierarchical taxonomies instead of many custom taxonomies?
- Breadcrumbs and Categories
- Renaming default category taxonomy?
- Conditional Site Logo(Category Based)
- Profiling user with categories
- Search by tag, category and author without plugin
- Images appear in the header on all pages, but not category.php
- Style a category page the same way as the homepage?
- List only child categories a post is in, of a specific parent category in wordpress
- show only terms from parent category
- Ajax Response Error
- Making my category headers smaller
- show posts in archive page based on selected catagory
- Need help to structure our a complex hierarchy
- Adding a category view to a page