Limit tag cloud terms by date

I’ve been looking for a plugin that limits the tags dislayed in the tag cloud by date. Basically, I want all tags from a certain date forward. I’ve searched current plugins and haven’t found anything that limits by date.

Doing some research, I think I just need to modify the following line from:

Read More
$tags = get_terms( 
    $args['taxonomy'], 
    array_merge( 
        $args, 
        array( 'orderby' => 'count', 'order' => 'DESC' ) 
    ) 
); // Always query top tags

to:

$tags = get_terms( 
    $args['taxonomy'], 
    array_merge( 
        $args, 
        array( 'orderby' => 'date', 'order' => 'DESC' ) 
    )
); // Always query top tags

in the wp_tag_cloud() function, but I’m still missing how to limit by the date. Suggestions?

Thanks!

Related posts

Leave a Reply

2 comments

  1. Well it’s not that it’s not possible it just means it will take some effort. I am able to use an SQL query that combines the posts, term_relationships and terms tables. This allows a tag or name to be associated with a post which was published on a particular date. This was the sql statement i used ->

    select * from lwdev_posts p JOIN lwdev_term_relationships r ON p.id=r.object_id JOIN lwdev_terms t ON r.term_taxonomy_id=t.term_id where p.post_status='publish'
    

    If you are not familiar with SQL this basically means combine the three tables and show all columns that are published.

    You can narrow this down to just the term and the date with the following ->

    select p.post_date, t.name from lwdev_posts p JOIN lwdev_term_relationships r ON p.id=r.object_id JOIN lwdev_terms t ON r.term_taxonomy_id=t.term_id where p.post_status='publish'
    

    So you have some data you can work with to produce your tag cloud. If you want to specify a date range then use the following ->

     select p.post_date, t.name from lwdev_posts p JOIN lwdev_term_relationships r ON p.id=r.object_id JOIN lwdev_terms t ON r.term_taxonomy_id=t.term_id where p.post_status='publish'
        AND p.post_date BETWEEN '2012-07-24' AND '2012-08-01' 
    

    Replace lwdev_ with your table prefix. Using some php and searching for a custom tag cloud method you will be able to use the sql to return all the terms, and then use some php to specify the date.

    One thing to note if you do not GROUP BY the term name then you will get a list of the same terms associated with a different post date. If you do GROUP BY the name then it will choose the earliest post date.

    Check the sql in phpmyadmin and test the query to tailor your results. Hopefully someone has written an easier way to do all this, you might need some custom php functions to get the desired effect but it seems possible, just laborious. Hope this in some way helps.

  2. NOT POSSIBLE –

    WordPress doesn’t store date information with the categories or tags, thats why we can not either sort them or limit them by their dates.

    Also there is no such argument – 'orderby' => 'date' for get_terms() function.

    See the Codex documentation on Possible Parameters.