I solved this with following code:
$currentCategoryId = wp_get_object_terms($post->ID, 'article-category', array('fields' => 'ids'));
if (is_array($currentCategoryId) && !empty($currentCategoryId[0])) {
$currentCategoryId = (int)$currentCategoryId[0];
}
$cat_args = array(
'taxonomy' => 'article-category',
'orderby' => 'menu_order',
'order' => 'ASC',
'hierarchical' => true,
'parent' => 0,
'hide_empty' => true,
'child_of' => 0
);
$get_categories = get_categories( $cat_args );
$categories = array();
foreach ($get_categories as $index => $category) {
$categories[$index]['id'] = $category->cat_ID;
$categories[$index]['slug'] = $category->slug;
$categories[$index]['name'] = $category->name;
}
$articles = array();
foreach ($categories as $index => $category) {
$args = array(
'post_type' => 'article',
'post_status' => 'publish',
'posts_per_page' => -1,
'tax_query' => array(
array (
'taxonomy' => 'article-category',
'field' => 'slug',
'terms' => $category['slug'],
)
)
);
$articles[$index]['category']['id'] = $category['id'];
$articles[$index]['category']['name'] = $category['name'];
$articles[$index]['category']['slug'] = $category['slug'];
$posts_array = get_posts( $args );
foreach ($posts_array as $key => $_post) {
$articles[$index]['posts'][$key]['id'] = $_post->ID;
$articles[$index]['posts'][$key]['title'] = $_post->post_title;
$articles[$index]['posts'][$key]['permalink'] = get_permalink($_post->ID);
}
}
wp_reset_postdata();