WordPress.org

Make WordPress Core

Changeset 37683


Ignore:
Timestamp:
06/11/2016 03:48:03 AM (3 years ago)
Author:
boonebgorges
Message:

Introduce term_taxonomy_id parameter for WP_Term_Query.

Allows the fetching of terms based on term_taxonomy_id, or an array of
term_taxonomy_ids.

Props spacedmonkey.
Fixes #37074.

Location:
trunk
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-term-query.php

    r37577 r37683  
    9393     *
    9494     * @since 4.6.0
     95     * @since 4.6.0 Introduced 'term_taxonomy_id' parameter.
    9596     * @access public
    9697     *
     
    137138     *     @type string|array $slug                   Optional. Slug or array of slugs to return term(s) for.
    138139     *                                                Default empty.
     140     *     @type int|array    $term_taxonomy_id       Optional. Term taxonomy ID, or array of term taxonomy IDs,
     141     *                                                to match when querying terms.
    139142     *     @type bool         $hierarchical           Whether to include terms that have non-empty descendants (even
    140143     *                                                if $hide_empty is set to true). Default true.
     
    184187            'name'                   => '',
    185188            'slug'                   => '',
     189            'term_taxonomy_id'       => '',
    186190            'hierarchical'           => true,
    187191            'search'                 => '',
     
    471475                $slug = sanitize_title( $args['slug'] );
    472476                $this->sql_clauses['where']['slug'] = "t.slug = '$slug'";
     477            }
     478        }
     479
     480        if ( ! empty( $args['term_taxonomy_id'] ) ) {
     481            if ( is_array( $args['term_taxonomy_id'] ) ) {
     482                $tt_ids = implode( ',', array_map( 'intval', $args['term_taxonomy_id'] ) );
     483                $this->sql_clauses['where']['term_taxonomy_id'] = "tt.term_taxonomy_id IN ({$tt_ids})";
     484            } else {
     485                $this->sql_clauses['where']['term_taxonomy_id'] = $wpdb->prepare( "tt.term_taxonomy_id = %d", $args['term_taxonomy_id'] );
    473486            }
    474487        }
Note: See TracChangeset for help on using the changeset viewer.