All you need to do is to add another query in your code:
function categorie_shortcode_callback() {
$html="";
$categories = get_categories( array(
// 'type' => 'carte', <- THERE IS NO ATTRIBUTE CALLED type FOR get_categories, SO REMOVE THAT
'taxonomy' => 'carte-category',
'parent' => 0
));
shuffle( $categories);
// you also don't need to loop through that array, since you only want to get first one
if ( ! empty($categories) ) {
$category = $categories[0];
$html.= '<h3> '. $category->name. '</h3>';
$html.= '<p class="txtContent"> '. $category->description. '</p>';
$random_posts = get_posts( array(
'post_type' => 'carte',
'posts_per_page' => 1,
'orderby' => 'rand',
'fields' => 'ids',
'tax_query' => array(
array( 'taxonomy' => 'carte-category', 'terms' => $category->term_id, 'field' => 'term_id' )
)
) );
if ( ! empty($random_posts) ) {
$html .= get_the_post_thumbnail( $random_posts[0] );
}
}
return $html;
}
add_shortcode( 'categorie', 'categorie_shortcode_callback' );