我正在尝试使用wp_dropdown_categories
获取当前类别的子类别。试图获取当前类别的子类别
onclick类别,我想要获取子类别。我曾尝试使用get_categories
函数与参数,但它不给我子类别。虽然使用has_children
给我空白阵列。
这是我的代码:
add_action('wp_ajax_wp_get_subcategory', 'wp_get_subcategory');
function wp_get_subcategory() {
$parent_cat_ID = $_POST['selected_category'];
$args = array(
'child_of' => $parent_cat_ID,
'taxonomy' => 'download_category',
'hide_empty' => 0,
'hierarchical' => false,
'depth' => 1,
'parent' => $parent_cat_ID
);
if (isset($parent_cat_ID)) {
$has_children = get_categories($args);
if ($has_children) {
//wp_dropdown_categories($args);
foreach ($has_children as $category) {
$option = '<option value="'.$category->cat_ID.'">';
$option .= $category->cat_name;
echo $option .= '</option>';
}
} else {
?><select name="sub_cat_disabled" id="sub_cat_disabled" disabled="disabled"><option>No child categories!</option></select><?php
}
die();
}
}
现在我正在获取子类别谢谢 – Bhavesh