Ticket #36950: 36950.patch
File 36950.patch, 2.1 KB (added by , 9 years ago) |
---|
-
src/wp-includes/taxonomy.php
927 927 return false; 928 928 } 929 929 930 $tax_clause = $wpdb->prepare( "AND tt.taxonomy = %s", $taxonomy );931 932 930 if ( 'slug' == $field ) { 933 $_field = 't.slug';934 931 $value = sanitize_title($value); 935 if ( empty( $value) )932 if ( empty( $value ) ) { 936 933 return false; 934 } 935 $terms = get_terms( array( 936 'taxonomy' => $taxonomy, 937 'hide_empty' => false, 938 'number' => 1, 939 'slug' => $value 940 ) ); 941 if ( empty( $terms ) || is_wp_error( $terms ) ) { 942 return false; 943 } 944 $term = array_shift( $terms ); 937 945 } elseif ( 'name' == $field ) { 938 946 // Assume already escaped 939 947 $value = wp_unslash($value); 940 $_field = 't.name'; 948 $terms = get_terms( array( 949 'taxonomy' => $taxonomy, 950 'hide_empty' => false, 951 'number' => 1, 952 'name' => $value 953 ) ); 954 if ( empty( $terms ) || is_wp_error( $terms ) ) { 955 return false; 956 } 957 $term = array_shift( $terms ); 941 958 } elseif ( 'term_taxonomy_id' == $field ) { 942 959 $value = (int) $value; 943 960 $_field = 'tt.term_taxonomy_id'; 944 961 945 // No `taxonomy` clause when searching by 'term_taxonomy_id'. 946 $tax_clause = ''; 962 $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 ) . " LIMIT 1" ); 963 if ( ! $term ) { 964 return false; 965 } 947 966 } else { 948 967 $term = get_term( (int) $value, $taxonomy, $output, $filter ); 949 968 if ( is_wp_error( $term ) || is_null( $term ) ) { … … 952 971 return $term; 953 972 } 954 973 955 $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" );956 if ( ! $term )957 return false;958 959 974 // In the case of 'term_taxonomy_id', override the provided `$taxonomy` with whatever we find in the db. 960 975 if ( 'term_taxonomy_id' === $field ) { 961 976 $taxonomy = $term->taxonomy;