Support

Account

Forum Replies Created

  • 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; 
  • You and thank you.
    I created a taxonomy field, print 1.
    I connected the custom post type “innovators” to the taxonomy field.
    So any innovator can have one or more connections to the tag (print 2).
    The post innovator type was created as a data sheet.
    Now I’m trying to create a google map (print 3) with all the “innovators” post, and I would like to filter the map to tags.
    The problem is that, as we see from the print 3, I do not need all tags but only those associated with post innovators, and being post a registry card, it makes no sense to tag a person (because in the archives tags also appear post type “innovators”), so I decided to simply associate a taxonomy with taxonomies field ACF. In this way it creates a relationship between the post and the tag, but the post is not actually tagged.
    As a result it could use, instead of a list of tags, currently obtained with get_terms, only list the total tags associated with the tassomomie field (no repeats of course, and with the number of associations).
    The final idea is a bit like in print 4.
    Thank you and I hope I was a little bit more clear 🙂

Viewing 2 posts - 1 through 2 (of 2 total)