[wp-trac] [WordPress Trac] #36846: Allow get_terms() to return slug&name fields
WordPress Trac
noreply at wordpress.org
Sun May 15 21:58:23 UTC 2016
#36846: Allow get_terms() to return slug&name fields
--------------------------+-----------------------------
Reporter: ramiy | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Taxonomy | Version:
Severity: normal | Keywords:
Focuses: performance |
--------------------------+-----------------------------
When we use the
[https://developer.wordpress.org/reference/functions/get_terms/
get_terms()] function, we can choose not to return the complete term
objects but a smaller array with predefined fields (for performance).
it's done using `fields` argument:
{{{
$terms = get_terms( array(
'taxonomy' => 'post_tag',
'fields' => 'all',
) );
}}}
Currently, the `fields` argument supports the following:
* `all` - returns an array of complete term objects. (DEFAULT)
* `ids` - returns an array of ids.
* `names` - returns an array of term names.
* `count` - returns the number of matching terms.
* `id=>parent` - returns an associative array with ids as keys, parent
term IDs as values.
* `id=>name` - returns an associative array with ids as keys, term names
as values.
* `id=>slug` - returns an associative array with ids as keys, term slugs
as values.
The problem is that in a growing number of websites I need to return only
term-slugs and term-names.
My patch adds another variation to the `fields` argument:
* `slug=>name` - returns an associative array with term slugs as keys,
term names as values.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/36846>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list