You could use get_categories()
.
Returns an array of category objects matching the query parameters.
Arguments are pretty much the same as wp_list_categories and can be passed as either array or in query syntax.
// Fetch parent categories
$parent_categories = get_categories( 'parent=0' );
foreach ( $parent_categories as $parent_category ) {
// Fetch child categories
$args = array(
'parent' => $parent_category->term_id
);
$categories = get_categories( $args );
foreach ( $categories as $category ) {
printf( '<div>%s</div>', $category->name );
}
}
This is a very simple example of the code without extra parameters like hide_empty
, type
etc.