• I have two custom post types called distributors and installers. They share a taxonomy called states.

    What I want to do is display a page listing all the states for the installers and a page listing all the states for the distributors. There will be installers and distributors in the same state.

    I have created a page template and assigned it to their respective pages. The problem I am running into is each page is pulling in the states from both post types.

    How can I create a page which only shows the states for the defined post type?

    $terms = get_terms ( 'prfx_states' );
    
    	if (count($terms)) {
    		echo "<ul>";
    	}
    	foreach ($terms as $term) {
    		$wpq = array (
    					'taxonomy' => 'prfx_states',
    	            	'order' => 'ASC',
    					'term' => $term->slug,
    					'post_type' => 'prfx_installers',
    				);
    		$query = new WP_Query ($wpq);
    		$article_count = $query->post_count;
    
    		echo "<li>";
    		if ($article_count) {
    			echo "<a href=\"/states/".$term->slug."\">".$term->name."</a>";
    		} else {
    			echo $term->name;
    		}
    		echo "</li>";
    
    	}
    	if (count($terms)) {
    		echo "</ul>";
    	}
  • The topic ‘2 Custom Post Types Sharing 1 Taxonomy Term’ is closed to new replies.