From 0982df4801a495320846a7a0a878cfa64c58d804 Mon Sep 17 00:00:00 2001 From: ryan Date: Thu, 22 Jan 2009 22:59:29 +0000 Subject: [PATCH] Don't limit query when descending hierarchy. Props filosofo. fixes #8832 git-svn-id: http://svn.automattic.com/wordpress/trunk@10416 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/taxonomy.php | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/wp-includes/taxonomy.php b/wp-includes/taxonomy.php index 8e4977f00..8601e9965 100644 --- a/wp-includes/taxonomy.php +++ b/wp-includes/taxonomy.php @@ -736,14 +736,15 @@ function &get_terms($taxonomies, $args = '') { if ( $hide_empty && !$hierarchical ) $where .= ' AND tt.count > 0'; - if ( !empty($number) ) { + // don't limit the query results when we have to descend the family tree + if ( ! empty($number) && ! $hierarchical && empty( $child_of ) && '' == $parent ) { if( $offset ) - $number = 'LIMIT ' . $offset . ',' . $number; + $limit = 'LIMIT ' . $offset . ',' . $number; else - $number = 'LIMIT ' . $number; + $limit = 'LIMIT ' . $number; } else - $number = ''; + $limit = ''; if ( !empty($search) ) { $search = like_escape($search); @@ -758,13 +759,11 @@ function &get_terms($taxonomies, $args = '') { else if ( 'names' == $fields ) $select_this = 't.term_id, tt.parent, tt.count, t.name'; - $query = "SELECT $select_this FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy IN ($in_taxonomies) $where ORDER BY $orderby $order $number"; + $query = "SELECT $select_this FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy IN ($in_taxonomies) $where ORDER BY $orderby $order $limit"; + $terms = $wpdb->get_results($query); if ( 'all' == $fields ) { - $terms = $wpdb->get_results($query); update_term_cache($terms); - } else if ( ('ids' == $fields) || ('names' == $fields) ) { - $terms = $wpdb->get_results($query); } if ( empty($terms) ) { @@ -812,6 +811,10 @@ function &get_terms($taxonomies, $args = '') { $terms = $_terms; } + if ( 0 < $number && intval(@count($terms)) > $number ) { + $terms = array_slice($terms, $offset, $number); + } + wp_cache_add( $cache_key, $terms, 'terms' ); $terms = apply_filters('get_terms', $terms, $taxonomies, $args);