I'm looking to display a list of the top 5 most used tags within a category over 30 days and the top of category.php I found a post that got me almost there but I don't know how filter it by category. Here is what I have:
global $wpdb;
$term_ids = $wpdb->get_col("
SELECT term_id , count(*) cont FROM $wpdb->term_taxonomy
INNER JOIN $wpdb->term_relationships ON $wpdb- >term_taxonomy.term_taxonomy_id=$wpdb->term_relationships.term_taxonomy_id
INNER JOIN $wpdb->posts ON $wpdb->posts.ID = $wpdb->term_relationships.object_id
WHERE DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= $wpdb->posts.post_date AND $wpdb->term_taxonomy.taxonomy='post_tag'
GROUP BY term_id
ORDER BY cont DESC
LIMIT 5
");
if ( count( $term_ids ) > 0 ) {
$tags = get_tags( array(
'orderby' => 'count',
'order' => 'DESC',
'number' => 5,
'include' => $term_ids,
) );
foreach ( (array) $tags as $tag ) {
echo '<li><a href="' . get_tag_link ($tag->term_id) . '" rel="tag">' .
$tag->name . '</a></li>';
}
}