WordPress.org

Make WordPress Core

Ticket #8832: number_get_terms_fix.diff

File number_get_terms_fix.diff, 1.8 KB (added by filosofo, 7 years ago)
  • wp-includes/taxonomy.php

     
    736736        if ( $hide_empty && !$hierarchical ) 
    737737                $where .= ' AND tt.count > 0'; 
    738738 
    739         if ( !empty($number) ) { 
     739        // don't limit the query results when we have to descend the family tree  
     740        if ( ! empty($number) && ! $hierarchical && empty( $child_of ) && '' == $parent ) { 
    740741                if( $offset ) 
    741                         $number = 'LIMIT ' . $offset . ',' . $number; 
     742                        $limit = 'LIMIT ' . $offset . ',' . $number; 
    742743                else 
    743                         $number = 'LIMIT ' . $number; 
     744                        $limit = 'LIMIT ' . $number; 
    744745 
    745746        } else 
    746                 $number = ''; 
     747                $limit = ''; 
    747748 
    748749        if ( !empty($search) ) { 
    749750                $search = like_escape($search); 
     
    758759        else if ( 'names' == $fields ) 
    759760                $select_this = 't.term_id, tt.parent, tt.count, t.name'; 
    760761 
    761         $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"; 
     762        $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"; 
    762763 
     764        $terms = $wpdb->get_results($query); 
    763765        if ( 'all' == $fields ) { 
    764                 $terms = $wpdb->get_results($query); 
    765766                update_term_cache($terms); 
    766         } else if ( ('ids' == $fields) || ('names' == $fields) ) { 
    767                 $terms = $wpdb->get_results($query); 
    768767        } 
    769768 
    770769        if ( empty($terms) ) { 
     
    812811                $terms = $_terms; 
    813812        } 
    814813 
     814        if ( 0 < $number && intval(@count($terms)) > $number ) { 
     815                $terms = array_slice($terms, $offset, $number); 
     816        } 
     817 
    815818        wp_cache_add( $cache_key, $terms, 'terms' ); 
    816819 
    817820        $terms = apply_filters('get_terms', $terms, $taxonomies, $args);