views:

256

answers:

3

I need to create a function for WP that will check if the current category is both child of X category and parent to Z category.

Ideas?

+2  A: 

Untested MySQL query to get you started:

SELECT x.cat_ID, y.cat_ID, z.cat_ID
FROM   categories y,
    LEFT JOIN categories x ON y.parent = x.cat_ID,
    LEFT JOIN categories z ON z.parent = y.cat_ID,
WHERE  y.cat_name = ? AND
       x.cat_name = ? AND
       z.cat_name = ?
djc
+1  A: 

Try this:

<?php
$catid = get_query_var('cat');
if (cat_is_ancestor_of($catid,$test_child_cat) && cat_is_ancestor_of($test_parent_cat,$catid)) {
echo "Current Category is child of X and Parent of Y";
}
?>
Adam Dempsey
+1  A: 

I finally got to write this simple solution for getting both Parent and Children form the current viewed category in Wordpress:

  $children = $wp_query->query_vars[category__in];
  $count = 0;

  echo 'Parent: ' . $wp_query->queried_object->parent;
        echo ' | ';
  echo 'Children: ';

  foreach ($children as $child) { 
   if (($wp_query->query_vars[category__in][$count]) != ($wp_query->query_vars[cat])) {
     echo $wp_query->query_vars[category__in][$count];
     echo ' ';
    }
   $count++;
  }

konzepz