I added a custom meta to my categories, and I want to just show the categories that have a certain meta value in dokan new product category dropdown, but I don’t know how to filter the category by meta value in the args of the function that gets the categories.
That´s the function that gets the categories.
$term = array();
$term = wp_get_post_terms( $post_id, 'product_cat', array( 'fields' => 'ids') );
include_once DOKAN_LIB_DIR.'/class.taxonomy-walker.php';
$drop_down_category = wp_dropdown_categories( apply_filters( 'dokan_product_cat_dropdown_args', array(
'show_option_none' => __( '', 'dokan-lite' ),
'hierarchical' => 1,
'hide_empty' => 0,
'name' => 'product_cat[]',
'id' => 'product_cat',
'taxonomy' => 'product_cat',
'title_li' => '',
'class' => 'product_cat dokan-form-control dokan-select2',
'exclude' => '',
'selected' => $term,
'echo' => 0,
'walker' => new TaxonomyDropdown( $post_id )
) ) );
2
Answers
I discovered that you can filter the category by meta key and value by adding these keys to the arguments array: meta_key, meta_value, and meta_compare.
You may refer to the
WP_TERM_QUERY
class.https://developer.wordpress.org/reference/classes/wp_term_query/__construct/
The example code as below: