mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-12 21:00:21 +00:00
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. git-svn-id: https://develop.svn.wordpress.org/trunk@36691 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -1719,8 +1719,13 @@ function get_terms( $args = array(), $deprecated = '' ) {
|
||||
$terms = $_terms;
|
||||
}
|
||||
|
||||
if ( $number && is_array( $terms ) && count( $terms ) > $number ) {
|
||||
$terms = array_slice( $terms, $offset, $number, true );
|
||||
// Hierarchical queries are not limited, so 'offset' and 'number' must be handled now.
|
||||
if ( $hierarchical && $number && is_array( $terms ) ) {
|
||||
if ( $offset >= count( $terms ) ) {
|
||||
$terms = array();
|
||||
} else {
|
||||
$terms = array_slice( $terms, $offset, $number, true );
|
||||
}
|
||||
}
|
||||
|
||||
wp_cache_add( $cache_key, $terms, 'terms', DAY_IN_SECONDS );
|
||||
|
||||
Reference in New Issue
Block a user