Skip to content

Instantly share code, notes, and snippets.

@iamayaz
Last active May 19, 2016 05:51
Show Gist options
  • Save iamayaz/5bec5a2a64dfaa179624 to your computer and use it in GitHub Desktop.
Save iamayaz/5bec5a2a64dfaa179624 to your computer and use it in GitHub Desktop.
Getting wordpress child categories data by parent category
// To getting the parent category by slug
$digital_post_cat = get_category_by_slug( 'digital-post' );
$digital_post_args = array(
'type' => 'post',
'child_of' => $digital_post_cat->term_id,
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => FALSE,
'hierarchical' => 1,
'taxonomy' => 'category',
);
// To getting the child categories
$digital_post_child_categories = get_categories($digital_post_args );
// Storing the child categories id in array()
$digital_child_list = array();
if ( !empty ( $digital_post_child_categories ) ){
foreach ( $digital_post_child_categories as $child_category ){
$digital_child_list[] = $child_category->term_id;
}
}
// To getting the child category information
foreach($digital_child_list as $child_Cat_ID){
$childData = get_category($child_Cat_ID);
echo $childData->name;
echo $childData->description;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment