Support

Account

Home Forums Front-end Issues Recall the tags that have a connection to the posts with field taxonomy Reply To: Recall the tags that have a connection to the posts with field taxonomy

  • Thank you so much James,
    following your instructions I wrote this code that the public can be useful to others, which makes me a list of the tags used with the number in parentheses. I will use it as a filter for google map. 🙂

    Ps I added “AND meta_value != ‘ ‘” to the query to avoid empty values

    	global $wpdb;
    	$query_tag_post = $wpdb->get_results( 
    	"
    	SELECT * FROM kgt_postmeta WHERE post_id IN (SELECT ID FROM kgt_posts WHERE post_type = 'innovatori') AND meta_key = 'tag_collegato' AND meta_value != ' '
    	"
    );
    
    	
    
    $meta_value = array();
    foreach($query_tag_post as $row) {
       
    	$meta_value[] = unserialize($row->meta_value);
    	
    }
    
    	foreach ($meta_value as $value){
    		foreach ($value as $num_tag){
    			$numeri_tags[] = $num_tag;
    		}
    	}
    	
    	
    
    	foreach ($numeri_tags as $numero_tag){
    		$termine = get_term_by('term_taxonomy_id', $numero_tag, 'settore');
    		$nomi_tag[] = $termine->name;
    		$slug_tag[] = $termine->slug;
    	}
    
    	
    	
    	
    	$stringa = array(); 
    foreach ($nomi_tag as $nome_tag) { 
            $c = array_count_values($nomi_tag); 
            $n = $c[$nome_tag]; 
            $stringa[array_search($nome_tag, $nomi_tag)] = $nome_tag . "(" . $n . ")";    
    } 
    $stringa = implode(',', $stringa); 
    
    echo $stringa;