How do I hide an empty category outside the loop?
-
‘m working on a wordpress site for a restaurant that has multiple locations so my categories are set up like this:
Locations (parent category)
-Location 1
-Location 2 etc. (child categories)Menu Items (parent category)
-Type 1
-Type 2 (child catgegories)All menu posts (custom Post type) are assigned at least one Location category and at least one Menu Item Type (pizza, burgers, beers)
SO I need to hide a Menu Item Type if it does not have any posts for that particular location. So location 1 could have pizza, burgers and beers and location two may only have pizza and beers.
<?php $thePage = $post->post_title; echo $thePage; ?>
<?php
$theLocations = array(
‘posts_per_page’ => 100,
‘post_type’ => ‘food-items’,
‘category_name’ => $thePage //Location name (Location 2, etc.)
);query_posts($theLocations);
// get all the categories from the database
$cats = get_categories();
// loop through the categries
foreach ($cats as $cat) {$cat_id= $cat->term_id;
if(cat_is_ancestor_of(’19’, $cat)){
echo “<h1>”.$cat->name.”</h1>”;
//How do I hide this if this category (burgers)
//is empty for this location (location 2)?
- The topic ‘How do I hide an empty category outside the loop?’ is closed to new replies.