display a random post thumbnaim from a random category

I have 2 categories in my cutom post type:
Cat 1
Cat 2

I wish display a random category from this post type. I made this and it’s work:

function categorie(){

$global;
$args = array(‘type’ => ‘carte’, ‘taxonomy’ => ‘carte-category’, ‘parent’ => 0);
$categories = get_categories($args);
shuffle( $categories);
$i = 0;

foreach($categories as $category) {
$i++;
$categoryname= $category->name;
$html.= ‘<h3> ‘. $category->name. ‘</h3>’;
$html.= ‘<p class=”txtContent”> ‘. $category->description. ‘</p>’;

if (++$i == 2) break;

}

return $html;

}
add_shortcode( ‘categorie’, ‘categorie’ );

But now in this random category, I wish display a thumbnail from random post

To be clear:
Cat1 = Menus
Posts: Menu 1, menu 2…

Cat 2 = Dishes
Posts: Dish 1, Dish 2…

If my random cat is displaying Cat1, I need the thumbnail of Menu 1 or Menu 2

How can I do that ?

Read more here:: display a random post thumbnaim from a random category

Leave a Reply

Your email address will not be published. Required fields are marked *