WordPress.org

Ready to get started?Download WordPress

Forums

Get the most popular tags in last 7 days (4 posts)

  1. MrDanielson
    Member
    Posted 1 year ago #

    Hi everyone!

    On my site I want to get the most popular tags in the last 7 days. I have found a code for this, but it doesn't seem to work (http://wordpress.stackexchange.com/questions/48557/display-list-of-most-used-tags-in-the-last-30-days)

    My source code:

    <?php
    			$wpdb->show_errors();
                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 NOT term_id = '7302' AND DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= $wpdb->posts.post_date");
    
                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 class="trending-link"><a href="' . get_tag_link ($tag->term_id) . '" title="'.$tag->name.'" rel="tag" class="trending-topic">' . ucfirst($tag->name) . '</a></li>';
    				}
                } else {
    				echo "Der opstod en fejl. Vi beklager.";
    			}
                ?>

    As you can see the part "INTERVAL 7 DAY" should get the most popular tags in the last week, but it won't work. The rest of the code is working just fine - this is the last thing I need to get working, till I can launch the site :/

    Thanks.

  2. MrDanielson
    Member
    Posted 1 year ago #

    bump!

  3. MrDanielson
    Member
    Posted 1 year ago #

    Anyone???

  4. the2nd
    Member
    Posted 6 months ago #

    The same question!

    The code below is working, but it shows not the most used tags. I've just checked it. It doesn't show the real most used tags.

    <ul id="footer-tags"> <?php global $wpdb; $term_ids = $wpdb->get_col(" SELECT DISTINCT term_taxonomy_id FROM $wpdb->term_relationships INNER JOIN $wpdb->posts ON $wpdb->posts.ID = object_id WHERE DATE_SUB(CURDATE(), INTERVAL 90 DAY) <= $wpdb->posts.post_date"); if($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>'; } } ?> </ul>

Topic Closed

This topic has been closed to new replies.

About this Topic