So in order to do this, I needed to first do a for each loop, store the category slug as a variable, JAMterm
, and then use that in a query to pull one random thumbnail from the category.
Thanks to @Renishkhunt for helping me along the way to get this answer.
<?php
$taxonomyName = "category";
$terms = get_terms($taxonomyName,array('parent' => 79));
echo '<ul>';
foreach($terms as $term) {
echo '<li><a href="'.get_term_link($term->slug,$taxonomyName).'">'.$term->name.'</a><br/>';
$JAMterm = $term->slug;
global $wp_query;
$term = $wp_query->queried_object;
$args=array(
'orderby' => 'rand',
'posts_per_page' => 1,
'post_type' => 'post',
'tax_query' => array(
array(
'taxonomy' => 'category',
'field' => 'slug',
'terms' => $JAMterm
)
)
);
$new_query = null;
$new_query = new WP_Query($args);
while ($new_query->have_posts()) : $new_query->the_post();
the_post_thumbnail();
endwhile;
wp_reset_postdata();
echo '</li>';
}
echo '</ul>';
?>