Exclude Tags from get_the_tags

<?php
    $how_many_posts = 50;
    $exclude_these_term_ids = array(
       10,
       20,
       35,
    );
    $args = array(
        'posts_per_page' => $how_many_posts,
        'orderby' => 'date',
        'order' => 'DESC',
    );
    // get the last $how_many_posts, which we will loop over
    // and gather the tags of
    query_posts($args);
    //
    $temp_ids = array();
    while (have_posts()) : the_post(); 
        // get tags for each post
        $posttags = get_the_tags();
        if ($posttags) {
            foreach($posttags as $tag) {
                // store each tag id value
                // that is not in the $exclude_these_term_ids
                // array
                if (!in_array($tag->term_id, $exclude_these_term_ids)) {
                    $temp_ids[] = $tag->term_id;
                }
            }
        }
    endwhile;
    // we're done with that loop, so we need to reset the query now
    wp_reset_query();
    $id_string = implode(',', array_unique($temp_ids));
    // These are the params I use, you'll want to adjust the args
    // to suit the look you want    
    $args = array(
        'smallest'  => 15, 
        'largest'   => 15,
        'unit'      => 'px', 
        'number'    => 10,  
        'format'    => 'flat',
        'separator' => "\n&bull;\n",
        'orderby'   => 'count', 
        'order'     => 'DESC',
        'include'   => $id_string,  // only include stored ids
        'link'      => 'view', 
        'echo'      => true,

    );
    wp_tag_cloud( $args );
    ?>

Leave a Comment