You can do it like:
$args = array(
'post_type' => 'post_type_name', // or use default if you use standard
'numberposts' => 3, // or you can use 1 if you need only from last post.
'orderby' => 'date', //by dates to get lastest
'order' => 'DESC',
);
$posts = get_posts($args);
$recent_taxonomies = [];
foreach ($posts as $key => $post_data) {
$recent_taxonomies[] = get_the_terms( $post_data->ID, 'custom_taxonomy_name');
}
More about get_posts
https://codex.wordpress.org/Template_Tags/get_posts
More about get_the_terms
https://developer.wordpress.org/reference/functions/get_the_terms/
If you want create cloud tag from this you can base on returned objects and count
for each object, then based on it create cloud.
For simply tag cloud you could use (where $name
is a taxonomy name)
(it create cloud from whole taxonomy)
function tagsCloudByTerm($name){
$tags_out = null;
$tax_terms = get_terms($name);
$tags_out="<span class="tag-meta ">";
$tmp = [];
$max = 0;
if(!empty($tax_terms)):
foreach ($tax_terms as $term) :
if($max < $term->count){
$max = $term->count;
}
endforeach;
foreach ($tax_terms as $term) :
$percent = floor(($term->count / $max) * 100);
if ($percent < 20):
$class="smallest";
elseif ($percent >= 20 and $percent < 40):
$class="small";
elseif ($percent >= 40 and $percent < 60):
$class="medium";
elseif ($percent >= 60 and $percent < 80):
$class="large";
else:
$class="largest";
endif;
$term_link_url = get_term_link($term, $post_taxonomies[$tag_key]);
$tmp[] = '<a class="'.$class.'" href="'.$term_link_url.'" title="'.$term->name.'">'.$term->name.'</a>';
endforeach;
endif;
$tags_out .= implode(', ', $tmp);
unset($tmp);
$tags_out = $tags_out.'</span>';
return $tags_out ;
}