From 7c2e7f89958115a098dbe01c473cdd55d91e6076 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Wed, 11 Sep 2013 00:02:08 +0000 Subject: [PATCH] Add `term_taxonomy_id` to available fields in `get_term_by()`. Adds unit test. Props jchristopher. Fixes #21651. Built from https://develop.svn.wordpress.org/trunk@25334 git-svn-id: http://core.svn.wordpress.org/trunk@25296 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/taxonomy.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/wp-includes/taxonomy.php b/wp-includes/taxonomy.php index fa32393b45..6ddfeb00a2 100644 --- a/wp-includes/taxonomy.php +++ b/wp-includes/taxonomy.php @@ -954,7 +954,7 @@ function get_term($term, $taxonomy, $output = OBJECT, $filter = 'raw') { * @uses sanitize_term() Cleanses the term based on $filter context before returning. * @see sanitize_term_field() The $context param lists the available values for get_term_by() $filter param. * - * @param string $field Either 'slug', 'name', or 'id' + * @param string $field Either 'slug', 'name', 'id' (term_id), or 'term_taxonomy_id' * @param string|int $value Search for this term value * @param string $taxonomy Taxonomy Name * @param string $output Constant OBJECT, ARRAY_A, or ARRAY_N @@ -976,6 +976,9 @@ function get_term_by($field, $value, $taxonomy, $output = OBJECT, $filter = 'raw // Assume already escaped $value = wp_unslash($value); $field = 't.name'; + } else if ( 'term_taxonomy_id' == $field ) { + $value = (int) $value; + $field = 'tt.term_taxonomy_id'; } else { $term = get_term( (int) $value, $taxonomy, $output, $filter); if ( is_wp_error( $term ) )