From e631d34d506762a705397f11ad63e8367a698de8 Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Sat, 31 Dec 2005 21:53:13 +0000 Subject: [PATCH] Fallback to matching the leaf category if the full path doesn't match. Props David House. fixes #2161 git-svn-id: https://develop.svn.wordpress.org/trunk@3385 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/classes.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/wp-includes/classes.php b/wp-includes/classes.php index ae5f948661..4cba440b86 100644 --- a/wp-includes/classes.php +++ b/wp-includes/classes.php @@ -485,14 +485,21 @@ class WP_Query { $cat_path .= ($pathdir!=''?'/':'') . sanitize_title($pathdir); $all_cat_ids = get_all_category_ids(); - $q['cat'] = 0; + $q['cat'] = 0; $partial_match = 0; foreach ( $all_cat_ids as $cat_id ) { $cat = get_category($cat_id); if ( $cat->fullpath == $cat_path ) { $q['cat'] = $cat_id; break; + } elseif ( $cat->category_nicename == $q['category_name'] ) { + $partial_match = $cat_id; } } + + //if we don't match the entire hierarchy fallback on just matching the nicename + if (!$q['cat'] && $partial_match) { + $q['cat'] = $partial_match; + } $tables = ", $wpdb->post2cat, $wpdb->categories"; $join = " LEFT JOIN $wpdb->post2cat ON ($wpdb->posts.ID = $wpdb->post2cat.post_id) LEFT JOIN $wpdb->categories ON ($wpdb->post2cat.category_id = $wpdb->categories.cat_ID) ";