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
This commit is contained in:
ryan 2009-04-30 16:51:45 +00:00
parent c206ed413c
commit 11cbf4e3d7
2 changed files with 11 additions and 7 deletions

View File

@ -166,12 +166,17 @@ if ( empty($cats_per_page) )
$cats_per_page = 20; $cats_per_page = 20;
$cats_per_page = apply_filters('edit_categories_per_page', $cats_per_page); $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( $page_links = paginate_links( array(
'base' => add_query_arg( 'pagenum', '%#%' ), 'base' => add_query_arg( 'pagenum', '%#%' ),
'format' => '', 'format' => '',
'prev_text' => __('«'), 'prev_text' => __('«'),
'next_text' => __('»'), 'next_text' => __('»'),
'total' => ceil(wp_count_terms('category') / $cats_per_page), 'total' => ceil($num_cats / $cats_per_page),
'current' => $pagenum 'current' => $pagenum
)); ));

View File

@ -662,10 +662,10 @@ function &get_terms($taxonomies, $args = '') {
wp_cache_set('last_changed', $last_changed, 'terms'); wp_cache_set('last_changed', $last_changed, 'terms');
} }
$cache_key = "get_terms:$key:$last_changed"; $cache_key = "get_terms:$key:$last_changed";
$cache = wp_cache_get( $cache_key, 'terms' );
if ( $cache = wp_cache_get( $cache_key, 'terms' ) ) { if ( false !== $cache ) {
$terms = apply_filters('get_terms', $cache, $taxonomies, $args); $cache = apply_filters('get_terms', $cache, $taxonomies, $args);
return $terms; return $cache;
} }
if ( 'count' == $orderby ) if ( 'count' == $orderby )
@ -780,8 +780,7 @@ function &get_terms($taxonomies, $args = '') {
} }
if ( empty($terms) ) { if ( empty($terms) ) {
$cache[ $key ] = array(); wp_cache_add( $cache_key, array(), 'terms' );
wp_cache_set( 'get_terms', $cache, 'terms' );
$terms = apply_filters('get_terms', array(), $taxonomies, $args); $terms = apply_filters('get_terms', array(), $taxonomies, $args);
return $terms; return $terms;
} }