• I found this code was not how I wanted more, like showing up the last 5 post_tag added recently.

    <?php
    // get 20 latest posts, display the tags used on those posts
    $tag_array = array();
    $args=array(
      'post_type' => 'post',
      'post_status' => 'publish',
      'posts_per_page' => 20,
      'caller_get_posts'=> 1
      );
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      while ($my_query->have_posts()) : $my_query->the_post();
        $tag_args=array('orderby' => 'none');
        $tags = wp_get_post_terms( $post->ID , 'post_tag', $tag_args);
        foreach($tags as $tag) {
          $tag_array[$tag->term_id] = $tag->term_id;
        }
      endwhile;
    }
    if ($tag_array) {
      echo '<p>List of tags used on 20 latest posts</p>';
      foreach($tag_array as $post_tag) {
        $tag = get_term_by('ID',$post_tag, 'post_tag');
        echo '<p><a href="' . esc_attr(get_term_link($tag, 'category')) . '" title="' . sprintf( __( "View all posts in %s" ), $tag->name ) . '" ' . '>' . $tag->name.'</a><p> ';
      }
    }
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>

    Credits code: MichaelH

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Show 5 post_tag added or updated recently’ is closed to new replies.