• 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 (https://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.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter MrDanielson

    (@mrdanielson)

    bump!

    Thread Starter MrDanielson

    (@mrdanielson)

    Anyone???

    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>

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Get the most popular tags in last 7 days’ is closed to new replies.