Changeset 39454 for branches/4.7/src/wp-includes/taxonomy.php
- Timestamp:
- 12/03/2016 04:04:05 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/4.7/src/wp-includes/taxonomy.php
r39326 r39454 825 825 */ 826 826 function get_term_by( $field, $value, $taxonomy = '', $output = OBJECT, $filter = 'raw' ) { 827 global $wpdb; 827 828 828 829 // 'term_taxonomy_id' lookups don't require taxonomy checks. … … 831 832 } 832 833 833 if ( 'id' === $field || 'term_id' === $field ) { 834 $tax_clause = $wpdb->prepare( "AND tt.taxonomy = %s", $taxonomy ); 835 836 if ( 'slug' == $field ) { 837 $_field = 't.slug'; 838 $value = sanitize_title($value); 839 if ( empty($value) ) 840 return false; 841 } elseif ( 'name' == $field ) { 842 // Assume already escaped 843 $value = wp_unslash($value); 844 $_field = 't.name'; 845 } elseif ( 'term_taxonomy_id' == $field ) { 846 $value = (int) $value; 847 $_field = 'tt.term_taxonomy_id'; 848 849 // No `taxonomy` clause when searching by 'term_taxonomy_id'. 850 $tax_clause = ''; 851 } else { 834 852 $term = get_term( (int) $value, $taxonomy, $output, $filter ); 835 if ( is_wp_error( $term ) || null === $term) {853 if ( is_wp_error( $term ) || is_null( $term ) ) { 836 854 $term = false; 837 855 } … … 839 857 } 840 858 841 $args = array( 842 'get' => 'all', 843 'number' => 1, 844 'taxonomy' => $taxonomy, 845 'update_term_meta_cache' => false, 846 'orderby' => 'none', 847 ); 848 849 switch ( $field ) { 850 case 'slug' : 851 $args['slug'] = $value; 852 break; 853 case 'name' : 854 $args['name'] = $value; 855 break; 856 case 'term_taxonomy_id' : 857 $args['term_taxonomy_id'] = $value; 858 unset( $args[ 'taxonomy' ] ); 859 break; 860 default : 861 return false; 862 } 863 864 $terms = get_terms( $args ); 865 if ( is_wp_error( $terms ) || empty( $terms ) ) { 859 $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", $value ) . " $tax_clause LIMIT 1" ); 860 if ( ! $term ) 866 861 return false; 867 }868 869 $term = array_shift( $terms );870 862 871 863 // In the case of 'term_taxonomy_id', override the provided `$taxonomy` with whatever we find in the db. … … 873 865 $taxonomy = $term->taxonomy; 874 866 } 867 868 wp_cache_add( $term->term_id, $term, 'terms' ); 875 869 876 870 return get_term( $term, $taxonomy, $output, $filter );
Note: See TracChangeset
for help on using the changeset viewer.