Make WordPress Core


Ignore:
Timestamp:
02/24/2016 07:12:45 PM (11 years ago)
Author:
boonebgorges
Message:

Improve 'offset' calculation when querying for hierarchical terms.

When querying for terms in hierarchical taxonomies, get_terms() initially
queries for all matching terms, and then trims the located results based on the
$number and $offset arguments passed to the function. See #8832. However,
a flaw in the original logic meant that results were failing to be trimmed
properly in cases where $offset exceeds the total number of matching terms;
in these cases, we should force an empty array.

Props danielbachhuber.
Fixes #35935.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/taxonomy.php

    r36634 r36691  
    17201720        }
    17211721
    1722         if ( $number && is_array( $terms ) && count( $terms ) > $number ) {
    1723                 $terms = array_slice( $terms, $offset, $number, true );
     1722        // Hierarchical queries are not limited, so 'offset' and 'number' must be handled now.
     1723        if ( $hierarchical && $number && is_array( $terms ) ) {
     1724                if ( $offset >= count( $terms ) ) {
     1725                        $terms = array();
     1726                } else {
     1727                        $terms = array_slice( $terms, $offset, $number, true );
     1728                }
    17241729        }
    17251730
Note: See TracChangeset for help on using the changeset viewer.