Support » Plugin: Most Popular Tags » Feature request

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author maxpagels

    (@maxpagels)

    Agreed. I need to think about the implementation: if one wants to exclude tags in one or more categories, that would mean that tags that belong to two or more categories would be excluded, too.

    Thread Starter Rado

    (@jeriksson)

    I did some code that will get tags based on category, with exclude option, only problem is the query is to heavy for the database to execute everytime someone visits a page.

    Perhaps you can use this code and optimize it into your plugin and make something good out of it.

    $exclude_these_term_ids = array(1,2,3);
    $custom_query = new WP_Query('posts_per_page=-1&category_name=technology');
    if ($custom_query->have_posts()) :
    	while ($custom_query->have_posts()) : $custom_query->the_post();
    		$posttags = get_the_tags();
    		if ($posttags) {
    			foreach($posttags as $tag) {
     if (!in_array($tag->term_id, $exclude_these_term_ids)) {
    				$all_tags[] = $tag->term_id;
    			}
    		}
    }
    	endwhile;
    endif;
    
    $tags_arr = array_unique($all_tags);
    $tags_str = implode(",", $tags_arr);
    
    $args = array(
    'smallest'  => 11,
    'largest'   => 11,
    'unit'      => 'px',
    'number'    => 10,
    'orderby' => 'count',
    'order' => 'DESC',
    'format'    => 'list',
    'include'   => $tags_str,
    );
    wp_tag_cloud($args);

    This will display 10 most popular tags from category “technology” and exclude tags with ID 1,2,3.

    IF you could figure out a way to accomplish the same thing but not load the database so heavily let me know!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Feature request’ is closed to new replies.