I want to show a category only if a (custom) post is in that category AND region = $name for that post.

So, e.g. I have a custom post (type “business”) named “Mamma Mia” in child-category: “pizzerias” (and in parent-category “food”), and in region “Rotterdam” (custom taxonomy: “region”, custom taxonomy term: “rotterdam”).

=> display category “pizzerias” (and parent-category “food”)

Only, I have no clue how to accomplish this. I’d appreciate any help on this puzzle.

<?php 

// $filter = array('region'=>$name); 

$categories = get_categories(); 
foreach ($categories as $cat) 
{ 
    if($cat->parent < 1) 
    { 
    $cat_name = $cat->cat_name; 
    $catid = get_cat_ID( $cat_name ); 
    echo $cat_name. '<br/>'; 

    $args=array( 
      'orderby' => 'name', 
      'order' => 'ASC', 
      'child_of' => $catid 
      ); 
    $categories=get_categories($args); 
      foreach($categories as $category) {  
        echo '<a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a><br/>'; 
        }  

    } 
} 

// print_r($categories);  


?>

8 Answers
8

the intention is to show a list of
categories, but only those categories
that have posts where the custom
taxonomy region is set to Rotterdam

This is done in the Query Multiple Taxonomies plugin:

http://plugins.trac.wordpress.org/browser/query-multiple-taxonomies/trunk/core.php?rev=308185#L10

Leave a Reply

Your email address will not be published. Required fields are marked *