How can i show Wordpress categories with subcategories comma separated? I got the following, but it's not comma separated per subcategory.
I want so specify everything from category id "1" show all child categories comma separated.
$categories = get_categories(); // Current Category will retrive
foreach ( $categories as $category ) {
$cat = $category->name; // Parent Category name
$category = get_category_by_slug( $cat );
$args = array(
'type' => 'post',
'child_of' => $category->term_id,
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => FALSE,
'hierarchical' => 1,
'taxonomy' => 'category',
);
$child_categories = get_categories($args );
$category_list = array();
$category_list[] = $category->term_id;
if ( !empty ( $child_categories ) ){ // If child Category available
foreach ( $child_categories as $child_category ){ // Print Child Category
$category_list[] = $child_category->term_id;
echo ",". $child_category->cat_name."<br/>";
}
}
}