maybe your children are empty, if so, they will not show up by default. you have to set the hide_empty
argument to true
. plus i cleaned your array a little, first you create one, and than in the next line you add more arguments. keep your code clean..
$optsetlect = (isset($_REQUEST['product_cat']) && !empty($_REQUEST['product_cat'])) ? $_REQUEST['product_cat'] : 0;
$args = [
'show_option_all' => esc_html__( 'All Categories', 'woocommerce' ),
'hierarchical' => 1,
'class' => 'cate-dropdown hidden-xs',
'value_field' => 'slug',
'selected' => $optsetlect,
'taxonomy' => 'product_cat',
'name' => 'product_cat',
'hide_empty' => 0,
];
wp_dropdown_categories($args);
echo true
& orderby ID
is also default, so there is no need to set these. check the docs for further arguments. and since you change value_field
you might check this here as well:
selected
(integer|string) (optional) Which category ID is initially selected in the dropdown. The type of value should match the ‘value_field’, which is term_id by default. For example, if ‘value_field’ is set to “slug”, then ‘selected’ will take a slug instead of an ID.
aka your $_REQUEST variable contains a slug, correct?!