Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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:

$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!

share|improve this question
1  
Do you mean the last used tags or the last created tags? –  toscho Aug 6 '12 at 19:53
add comment

2 Answers

up vote 1 down vote accepted

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.

share|improve this answer
    
+1 for the effort and the solution. Maybe you want to consider using one of the $wpdb methods for this? –  kaiser Aug 7 '12 at 17:35
    
@kaiser true true, i tested it on phpmyadmin to see if i could obtain the data, since that was successful i imagined the remainder of the hardwork would be done by the developer. I am sure something like ---- $wpdb->query("select p.post_date, t.name from tablePrefix_posts p JOIN tablePrefix_term_relationships r ON p.id=r.object_id JOIN tablePrefix_terms t ON r.term_taxonomy_id=t.term_id where p.post_status='publish' AND p.post_date BETWEEN '%s' AND '%s'", $firstDate, $secondDate); thanks for the upvote =) –  thirdOctet Aug 8 '12 at 13:36
    
Hint: You can use the "edit" link to add/edit your answer ;) –  kaiser Aug 8 '12 at 14:04
add comment

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.

share|improve this answer
    
Thank you. I should have started with the Codex. So it sounds like I should be looking at pulling the tags for all the posts made after a certain date instead of trying to make the tag functions work with a date, correct? –  Yazmin Aug 6 '12 at 20:47
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.