For getting the posts related to each category you need to use get_posts( $args )
function and in $args
you can add your category_id
$args = array (
'post_type' => 'post',
'category' => $cat_ID,
'post_status' => 'publish',
);
$my_posts = get_posts( $args ); // return array of posts
// storing all post ID in an array
foreach( $my_posts as $my_post ) {
$post_cat_name[] = $my_post['ID'];
}
So in $post_cat_name
it will store all the post id related to your $cat_ID
If you want these to be done for 3 $cat_id
, then you can loop the above code for 3 $cat_id
and you can use $post_cat_name
array as 2D array
.