How to limit the wordpress tagcloud by date?
Okay, so what I think you probably want is to do this for say, the last 50 posts.
Loop over the last n
posts, extract the term_id
of each tag for each post, then pass that string into the include
argument of 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 ofquery_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 nowwp_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 );