Ticket #29942: taxonomy.php.patch
File taxonomy.php.patch, 3.9 KB (added by , 10 years ago) |
---|
-
wp-includes/taxonomy.php
2280 2280 $taxonomies = "'" . implode("', '", $taxonomies) . "'"; 2281 2281 $object_ids = implode(', ', $object_ids); 2282 2282 2283 $select_this = ''; 2284 if ( 'all' == $fields ) 2285 $select_this = 't.*, tt.*'; 2286 else if ( 'ids' == $fields ) 2287 $select_this = 't.term_id'; 2288 else if ( 'names' == $fields ) 2289 $select_this = 't.name'; 2290 else if ( 'slugs' == $fields ) 2291 $select_this = 't.slug'; 2292 else if ( 'all_with_object_id' == $fields ) 2293 $select_this = 't.*, tt.*, tr.object_id'; 2283 $query = "SELECT * FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON tt.term_id = t.term_id INNER JOIN $wpdb->term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ($taxonomies) AND tr.object_id IN ($object_ids) $orderby $order"; 2284 2285 // Attempt to use cached query 2286 $key = md5( $query ); 2287 $last_changed = wp_cache_get( 'last_changed', 'terms' ); 2288 if ( ! $last_changed ) { 2289 $last_changed = microtime(); 2290 wp_cache_set( 'last_changed', $last_changed, 'terms' ); 2291 } 2292 $cache_key = "wp_get_object_terms:$key:$last_changed"; 2293 $cache = wp_cache_get( $cache_key, 'terms' ); 2294 2295 if ( false !== $cache ) { 2296 $_terms = $cache; 2297 } else { 2298 $_terms = $wpdb->get_results( $query ); 2299 wp_cache_set( $cache_key, $_terms, 'terms', DAY_IN_SECONDS ); 2300 } 2294 2301 2295 $query = "SELECT $select_this FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON tt.term_id = t.term_id INNER JOIN $wpdb->term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ($taxonomies) AND tr.object_id IN ($object_ids) $orderby $order";2296 2297 2302 $objects = false; 2298 2303 if ( 'all' == $fields || 'all_with_object_id' == $fields ) { 2299 $_terms = $wpdb->get_results( $query );2300 2304 foreach ( $_terms as $key => $term ) { 2301 2305 $_terms[$key] = sanitize_term( $term, $taxonomy, 'raw' ); 2302 2306 } 2307 2303 2308 $terms = array_merge( $terms, $_terms ); 2304 2309 update_term_cache( $terms ); 2305 2310 $objects = true; 2306 2311 } else if ( 'ids' == $fields || 'names' == $fields || 'slugs' == $fields ) { 2307 $_terms = $wpdb->get_col( $query );2308 2312 $_field = ( 'ids' == $fields ) ? 'term_id' : 'name'; 2309 2313 foreach ( $_terms as $key => $term ) { 2314 switch ( $fields ) { 2315 case 'ids' : 2316 $term = $term->term_id; 2317 break; 2318 2319 case 'names' : 2320 $term = $term->name; 2321 break; 2322 2323 case 'slugs' : 2324 $term = $term->slug; 2325 break; 2326 } 2327 2310 2328 $_terms[$key] = sanitize_term_field( $_field, $term, $term, $taxonomy, 'raw' ); 2311 2329 } 2312 2330 $terms = array_merge( $terms, $_terms ); 2313 2331 } else if ( 'tt_ids' == $fields ) { 2314 $terms = $wpdb->get_col("SELECT tr.term_taxonomy_id FROM $wpdb->term_relationships AS tr INNER JOIN $wpdb->term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tr.object_id IN ($object_ids) AND tt.taxonomy IN ($taxonomies) $orderby $order"); 2332 $query = "SELECT tr.term_taxonomy_id FROM $wpdb->term_relationships AS tr INNER JOIN $wpdb->term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tr.object_id IN ($object_ids) AND tt.taxonomy IN ($taxonomies) $orderby $order"; 2333 2334 // Attempt to use cached query 2335 $key = md5( $query ); 2336 $cache_key = "wp_get_object_terms:$key:$last_changed"; 2337 $cache = wp_cache_get( $cache_key, 'terms' ); 2338 2339 if ( false !== $cache ) { 2340 $terms = $cache; 2341 } else { 2342 $terms = $wpdb->get_col($query); 2343 wp_cache_set( $cache_key, $terms, 'terms', DAY_IN_SECONDS ); 2344 } 2345 2315 2346 foreach ( $terms as $key => $tt_id ) { 2316 2347 $terms[$key] = sanitize_term_field( 'term_taxonomy_id', $tt_id, 0, $taxonomy, 'raw' ); // 0 should be the term id, however is not needed when using raw context. 2317 2348 } … … 2334 2365 } elseif ( ! $objects ) { 2335 2366 $terms = array_values( array_unique( $terms ) ); 2336 2367 } 2368 2337 2369 /** 2338 2370 * Filter the terms for a given object or objects. 2339 2371 *