Update: Better one here https://voila-blog.com/mysql-get-tags-taxonomy-by-recent-posts-in-wordpress-db/ (MySQL)
If you want to display the most recent tags in WordPress, apply this code to the current theme’s functions.php
function most_recent_tags($args){
$limit = 10; //limit 10 tags by default
//Get limit tags argument from shortcode
$numargs = func_get_args();
if (isset($numargs['limit']) && filter_var($numargs['limit'], FILTER_VALIDATE_INT)){
$limit = $numargs['limit'];
}
$args=array(
'orderby'=>'term_id',
'order'=>'DESC',
'hide_empty'=>false,
'number' => $limit,
);
$tags = get_tags($args);
$trend_tags_html = '<div class="post_tags">';
foreach ( $tags as $tag ) {
$tag_link = get_tag_link( $tag->term_id );
$trend_tags_html .= "<a href='{$tag_link}' title='{$tag->name} Tag' class='{$tag->slug}'>";
$trend_tags_html .= "{$tag->name}</a>";
}
$trend_tags_html .= '</div>';
return $trend_tags_html;
}
add_shortcode('most_recent_tags','most_recent_tags');
In my case, I will get 20 most recent tags by using the shortcode:
[most_recent_tags limit=20]