| 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 | } |
| 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 | |