I am using this code to display my product categories in a custom form:
$product_cats = get_terms('product_cat');
$searchForm .= '<select class="asModalBoxes" id="partType" name="partType">';
foreach($product_cats as $product_cat) {
$searchForm .= "<option class='partOption' value='{$product_cat->name}'>{$product_cat->name}</option>";
}
$searchForm .= '</select><br><br>';
It works and shows every category. I need to narrow the options down to specific categories though (probably by category ID). Right now my only fix is to remove them with jQuery... but I have a TON of categories and it would be much more efficient to just pick which ones I need.
Any clue?
All you need to add a custom checkbox to category page via this plugin : Category and Taxonomy Meta Fields
And then check the meta condition for category , if checkbox was ticked , then you can include the category in dropdown. Use get_term_meta to get the custom meta field for category.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.