Make WordPress Core


Ignore:
Timestamp:
01/02/2015 09:33:33 PM (12 years ago)
Author:
boonebgorges
Message:

Introduce 'name' parameter for get_terms().

This enhancement requires a modification in the way that wp_dropdown_categories()
prepares its arguments for get_terms(), so that its unrelated 'name' param is
not mistaken for the new 'name' argument in get_terms().

Props danielbachhuber.
Fixes #30611.

File:
1 edited

Legend:

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

    r31012 r31024  
    15491549 *
    15501550 * @since 2.3.0
     1551 * @since 4.2.0 Introduced 'name' parameter.
    15511552 *
    15521553 * @global wpdb $wpdb WordPress database abstraction object.
     
    15791580 *                                           term objects), 'ids' or 'names' (returns an array of integers
    15801581 *                                           or strings, respectively. Default 'all'.
     1582 *     @type string|array $name              Optional. Name or array of names to return term(s) for. Default empty.
    15811583 *     @type string|array $slug              Optional. Slug or array of slugs to return term(s) for. Default empty.
    15821584 *     @type bool         $hierarchical      Whether to include terms that have non-empty descendants (even
     
    16191621        $defaults = array('orderby' => 'name', 'order' => 'ASC',
    16201622                'hide_empty' => true, 'exclude' => array(), 'exclude_tree' => array(), 'include' => array(),
    1621                 'number' => '', 'fields' => 'all', 'slug' => '', 'parent' => '',
     1623                'number' => '', 'fields' => 'all', 'name' => '', 'slug' => '', 'parent' => '',
    16221624                'hierarchical' => true, 'child_of' => 0, 'get' => '', 'name__like' => '', 'description__like' => '',
    16231625                'pad_counts' => false, 'offset' => '', 'search' => '', 'cache_domain' => 'core' );
     
    17941796        if ( ! empty( $exclusions ) ) {
    17951797                $where .= $exclusions;
     1798        }
     1799
     1800        if ( ! empty( $args['name'] ) ) {
     1801                if ( is_array( $args['name'] ) ) {
     1802                        $name = array_map( 'sanitize_text_field', $args['name'] );
     1803                        $where .= " AND t.name IN ('" . implode( "', '", $name ) . "')";
     1804                } else {
     1805                        $name = sanitize_text_field( $args['name'] );
     1806                        $where .= $wpdb->prepare( " AND t.name = %s", $name );
     1807                }
    17961808        }
    17971809
Note: See TracChangeset for help on using the changeset viewer.