• Hello,

    I got 2 types of taxonomy : Departement / Activity both for my custom post type “visite”.

    In the template taxonomy-departement.php i display all CPT visite with the current taxonomy department. Works, i’m happy =)
    I added an filter “$_GET[“activity_id”]”, with this function to redirect with the right variable :

    <script language="javascript">
    				function moveTo(optionValue) {
    				    if(optionValue=="") return false;
    					    window.location='https://www.mysite.com/departement/<?php echo $term_dept->slug;?>/?secteur_id='+optionValue;
    					}
    			</script>
            	<div class="quick-search">
            	<select onchange="moveTo(this.options[this.selectedIndex].value);">
    				<option value="">Sélectionnez un secteur d'activité</option>
    				<?php $terms_secteur = get_terms('secteur', 'orderby=name&order=ASC&hide_empty=0');
     						$count = count($terms_secteur);
     						if ( $count > 0 ){
         						foreach ( $terms_secteur as $term_secteur ) {
           						echo "<option value=". $term_secteur->term_id .">". $term_secteur->name ."</option>";
            					}
     						}
    				?>
    			</select>

    To get the second taxonomy, i used :
    $terms_secteur = get_terms('secteur', 'orderby=name&order=ASC&hide_empty=0');
    So i got all the terms of list.

    But i only want the terms who has CPT already tagged on my first taxonony (departement)…

    Same, used a function found on web to count CPT in specific taxonomy :

    function wt_get_custom_taxonomy_count($ptype,$pterm) {
    	global $wpdb;
    	$SQL  = "SELECT count(*) FROM $wpdb->posts posts, $wpdb->terms terms, $wpdb->term_relationships rels ";
    	$SQL .= "WHERE posts.post_status = 'publish' ";
    	$SQL .= "AND post_type = '".$ptype."' ";
    	$SQL .= "AND posts.ID = rels.object_id ";
    	if($pterm!=""):
    	$SQL .= "AND terms.slug = '".$pterm."' ";
    	endif;
    	$SQL .= "AND terms.term_id = rels.term_taxonomy_id";
    	return $wpdb->get_var($SQL);
    }

    But how can i have the count of the post which are in a taxo but tagged in a first taxo…

    Tell me if i’m not clear, bad my english…

    Thank

    Pop

  • The topic ‘Get Count/Terms List but hide if has no post in an other taxonomy’ is closed to new replies.