From 11cbf4e3d7911c5b8566dc3d623cdf94ec08ed2e Mon Sep 17 00:00:00 2001 From: ryan Date: Thu, 30 Apr 2009 16:51:45 +0000 Subject: [PATCH] Fix category search pagination. Fix caching of empty term results. Props Denis-de-Bernardy. fixes #8632 git-svn-id: http://svn.automattic.com/wordpress/trunk@11140 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/categories.php | 7 ++++++- wp-includes/taxonomy.php | 11 +++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/wp-admin/categories.php b/wp-admin/categories.php index 9ef2e050c7..6bc72aea48 100644 --- a/wp-admin/categories.php +++ b/wp-admin/categories.php @@ -166,12 +166,17 @@ if ( empty($cats_per_page) ) $cats_per_page = 20; $cats_per_page = apply_filters('edit_categories_per_page', $cats_per_page); +if ( !empty($_GET['s']) ) + $num_cats = count(get_categories(array('hide_empty' => 0, 'search' => $_GET['s']))); +else + $num_cats = wp_count_terms('category'); + $page_links = paginate_links( array( 'base' => add_query_arg( 'pagenum', '%#%' ), 'format' => '', 'prev_text' => __('«'), 'next_text' => __('»'), - 'total' => ceil(wp_count_terms('category') / $cats_per_page), + 'total' => ceil($num_cats / $cats_per_page), 'current' => $pagenum )); diff --git a/wp-includes/taxonomy.php b/wp-includes/taxonomy.php index ef81bdf7ec..068dae4ed1 100644 --- a/wp-includes/taxonomy.php +++ b/wp-includes/taxonomy.php @@ -662,10 +662,10 @@ function &get_terms($taxonomies, $args = '') { wp_cache_set('last_changed', $last_changed, 'terms'); } $cache_key = "get_terms:$key:$last_changed"; - - if ( $cache = wp_cache_get( $cache_key, 'terms' ) ) { - $terms = apply_filters('get_terms', $cache, $taxonomies, $args); - return $terms; + $cache = wp_cache_get( $cache_key, 'terms' ); + if ( false !== $cache ) { + $cache = apply_filters('get_terms', $cache, $taxonomies, $args); + return $cache; } if ( 'count' == $orderby ) @@ -780,8 +780,7 @@ function &get_terms($taxonomies, $args = '') { } if ( empty($terms) ) { - $cache[ $key ] = array(); - wp_cache_set( 'get_terms', $cache, 'terms' ); + wp_cache_add( $cache_key, array(), 'terms' ); $terms = apply_filters('get_terms', array(), $taxonomies, $args); return $terms; }