Thanks for the quick response guys~
Lance, I have WP 3.1 and I implemented your fix, but It still seems to not work. I picked through my code against yours, but there doesn’t seem to be anything wrong. I simply copied your code into the plugin’s php. Is there a different way to implement the fix?
this is the code i have for reference..
function get_category_title($node) {
global $wpdb;
$test = $wpdb->get_var("SELECT name FROM $wpdb->terms WHERE term_id=$node");
return $test;
}
function get_category_child() {
global $wp_query;
return $wp_query->query_vars['cat_child'];
}
function is_parent() {
global $wp_query;
if ((get_category_parent($wp_query->query_vars['cat']) == 0) && (empty($wp_query->query_vars['cat_child']))) {
return true;
} else {
return false;
}
}
function get_category_parent($node) {
$path = get_category_path($node);
if (empty($path)) {
return 0;
} else {
return $path[0];
}
}
function get_category_path($node) {
global $wpdb;
$parent = $wpdb->get_var("SELECT parent FROM $wpdb->term_taxonomy WHERE term_id=$node");
$path = array();
if ($parent != 0) {
$path[] = $parent;
$path = array_merge(get_category_path($parent), $path);
}
return $path;
}
function epct_redirect() {
global $wp_query;
if (is_category()) {
$childcat = $wp_query->query_vars['cat'];
$parent = get_category_parent($childcat);
$category = get_category($childcat);
if ($parent != 0) {
// fix from marty@halfempty to deal with custom template.
if (!file_exists(STYLESHEETPATH . '/category-' . $category->slug . '.php')) {
//fix for WP 3.1
$parent = get_category($parent);
$wp_query->queried_object->slug = $parent->slug;
}
}
}
// print_r($wp_query->query_vars);
}
add_action('template_redirect', 'epct_redirect');