Changeset 34679 for trunk/src/wp-includes/taxonomy-functions.php
- Timestamp:
- 09/29/2015 03:51:11 AM (10 years ago)
- File:
-
- 1 edited
-
trunk/src/wp-includes/taxonomy-functions.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/taxonomy-functions.php
r34538 r34679 782 782 * 783 783 * @since 2.3.0 784 * @since 4.4.0 `$taxonomy` is optional if `$field` is 'term_taxonomy_id'. 784 785 * 785 786 * @global wpdb $wpdb WordPress database abstraction object. … … 788 789 * @param string $field Either 'slug', 'name', 'id' (term_id), or 'term_taxonomy_id' 789 790 * @param string|int $value Search for this term value 790 * @param string $taxonomy Taxonomy Name791 * @param string $taxonomy Taxonomy name. Optional, if `$field` is 'term_taxonomy_id'. 791 792 * @param string $output Constant OBJECT, ARRAY_A, or ARRAY_N 792 793 * @param string $filter Optional, default is raw or no WordPress defined filter will applied. … … 794 795 * Will return false if $taxonomy does not exist or $term was not found. 795 796 */ 796 function get_term_by( $field, $value, $taxonomy, $output = OBJECT, $filter = 'raw') {797 function get_term_by( $field, $value, $taxonomy = '', $output = OBJECT, $filter = 'raw' ) { 797 798 global $wpdb; 798 799 799 if ( ! taxonomy_exists($taxonomy) ) 800 // 'term_taxonomy_id' lookups don't require taxonomy checks. 801 if ( 'term_taxonomy_id' !== $field && ! taxonomy_exists( $taxonomy ) ) { 800 802 return false; 803 } 804 805 $tax_clause = $wpdb->prepare( "AND tt.taxonomy = %s", $taxonomy ); 801 806 802 807 if ( 'slug' == $field ) { … … 812 817 $value = (int) $value; 813 818 $field = 'tt.term_taxonomy_id'; 819 820 // No `taxonomy` clause when searching by 'term_taxonomy_id'. 821 $tax_clause = ''; 814 822 } else { 815 823 $term = get_term( (int) $value, $taxonomy, $output, $filter ); … … 820 828 } 821 829 822 $term = $wpdb->get_row( $wpdb->prepare( "SELECT t.*, tt.* FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy = %s AND $field = %s LIMIT 1", $taxonomy, $value ) );830 $term = $wpdb->get_row( $wpdb->prepare( "SELECT t.*, tt.* FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE $field = %s $tax_clause LIMIT 1", $value ) ); 823 831 if ( ! $term ) 824 832 return false; 833 834 // In the case of 'term_taxonomy_id', override the provided `$taxonomy` with whatever we find in the db. 835 if ( 'term_taxonomy_id' === $field ) { 836 $taxonomy = $term->taxonomy; 837 } 825 838 826 839 wp_cache_add( $term->term_id, $term, $taxonomy );
Note: See TracChangeset
for help on using the changeset viewer.