Ticket #11904: is_tax.11904.diff
| File is_tax.11904.diff, 2.1 KB (added by , 16 years ago) |
|---|
-
wp-includes/query.php
221 221 } 222 222 223 223 /** 224 * Whether the current page query has the given taxonomy slug or contains taxonomy.224 * Whether the current query is for the given taxonomy and/or term. 225 225 * 226 * If no taxonomy argument is set, returns true if any taxonomy is queried. 227 * If the taxonomy argument is passed but no term argument, returns true 228 * if the taxonomy or taxonomies in the argument are being queried. 229 * If both taxonomy and term arguments are passed, returns true 230 * if the current query is for a term contained in the terms argument 231 * which has a taxonomy contained in the taxonomy argument. 232 * 226 233 * @since 2.5.0 227 234 * @uses $wp_query 228 235 * 229 * @param string|array $slug Optional. Slug or slugs to check in current query. 236 * @param string|array $taxonomy Optional. Slug or slugs to check in current query. 237 * @param int|array|string $term. Optional. The term's ID, array of term IDs, or term slug. 230 238 * @return bool 231 239 */ 232 function is_tax( $ slug= '' ) {233 global $wp_query ;240 function is_tax( $taxonomy = '', $term = '' ) { 241 global $wp_query, $wp_taxonomies; 234 242 235 if ( !$wp_query->is_tax ) 236 return false; 243 $queried_object = $wp_query->get_queried_object(); 244 $tax_array = (array) $taxonomy; 245 $term_array = (array) $term; 237 246 238 if ( empty($slug) ) 247 if ( 248 ( $wp_query->is_tax || $wp_query->is_category || $wp_query->is_tag ) && 249 ( 250 empty( $taxonomy ) || 251 count( array_intersect($tax_array, array_keys($wp_taxonomies)) ) && 252 ( 253 isset($queried_object->taxonomy) && 254 in_array($queried_object->taxonomy, $tax_array) && 255 ( 256 empty( $term ) || 257 ( 258 isset($queried_object->term_id) && 259 count(array_intersect( 260 array($queried_object->term_id, $queried_object->name, $queried_object->slug), 261 $term_array 262 )) 263 ) 264 ) 265 ) 266 ) 267 ) { 239 268 return true; 240 241 return in_array( get_query_var('taxonomy'), (array) $slug );269 } 270 return false; 242 271 } 243 272 244 273 /**