How to limit wordpress tagcloud by date?

I searched for quite a while to find a way to limit wordpress tags by date and arrange them by the number of times they appeared in the selected timeframe. But I was pretty unsatisfactory.

What I'm trying to achieve is something like trending topics on Twitter. But in this case, "trend labels." By default, the wordpress tagcloud displays the most popular tags of all time. Which makes no sense in my case, since I want to track current trends.

Ideally, it would be something like:

Most popular tags today

  • Obama (18 references)
  • New York (15 references)
  • Iron Man (11 references)
  • Robin Hood (7 references)

And then it multiplied by "most popular this week" and "most popular this month." Does anyone know how to achieve this?

+6
date tags limit wordpress
source share
4 answers

Okay, so I think you probably want to do this, say, the last 50 posts.

End the last messages n , term_id each tag for each message, then pass this line to the include argument wp_tag_cloud() ;

 $how_many_posts = 50; $args = array( 'posts_per_page' => $how_many_posts, 'orderby' => 'date', 'order' => 'DESC', ); // get the last $how_many_posts, which we will loop over // and gather the tags of query_posts($args); // $temp_ids = array(); while (have_posts()) : the_post(); // get tags for each post $posttags = get_the_tags(); if ($posttags) { foreach($posttags as $tag) { // store each tag id value $temp_ids[] = $tag->term_id; } } endwhile; // we're done with that loop, so we need to reset the query now wp_reset_query(); $id_string = implode(',', array_unique($temp_ids)); // These are the params I use, you'll want to adjust the args // to suit the look you want $args = array( 'smallest' => 10, 'largest' => 30, 'unit' => 'px', 'number' => 150, 'format' => 'flat', 'separator' => "\n", 'orderby' => 'count', 'order' => 'DESC', 'include' => $id_string, // only include stored ids 'link' => 'view', 'echo' => true, ); wp_tag_cloud( $args ); 
+3
source share

I am sure that tags do not have timestamps - perhaps you could search for messages with specific tags for a certain period of time?

0
source share

I think you can look at some of the plugins and see if you have a plugin like what you need

0
source share

Yo can get a list of request tags, so you don’t need to loop through the last X post.

 <ul id="footer-tags"> <?php $wpdb->show_errors(); ?> <?php global $wpdb; $term_ids = $wpdb->get_col(" SELECT term_id 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"); if(count($term_ids) > 0){ $tags = get_tags(array( 'orderby' => 'count', 'order' => 'DESC', 'number' => 28, 'include' => $term_ids, )); foreach ( (array) $tags as $tag ) { echo '<li><a href="' . get_tag_link ($tag->term_id) . '" rel="tag">' . $tag->name . '</a></li>'; } } ?> </ul> 
0
source share

All Articles