<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[13486] trunk/wp-includes/query.php: More powerful version is is_tax().</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/13486">13486</a></dd>
<dt>Author</dt> <dd>dd32</dd>
<dt>Date</dt> <dd>2010-02-28 05:59:39 +0000 (Sun, 28 Feb 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>More powerful version is is_tax(). Props filosofo, scribu. Adds $term parameter. Fixes <a href="http://trac.wordpress.org/ticket/11904">#11904</a></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpincludesqueryphp">trunk/wp-includes/query.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpincludesqueryphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/query.php (13485 => 13486)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/query.php        2010-02-28 04:27:32 UTC (rev 13485)
+++ trunk/wp-includes/query.php        2010-02-28 05:59:39 UTC (rev 13486)
</span><span class="lines">@@ -221,24 +221,43 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><del>- * Whether the current page query has the given taxonomy slug or contains taxonomy.
</del><ins>+ * Whether the current query is for the given taxonomy and/or term.
</ins><span class="cx">  *
</span><ins>+ * If no taxonomy argument is set, returns true if any taxonomy is queried.
+ * If the taxonomy argument is passed but no term argument, returns true 
+ *    if the taxonomy or taxonomies in the argument are being queried.
+ * If both taxonomy and term arguments are passed, returns true 
+ *    if the current query is for a term contained in the terms argument
+ *    which has a taxonomy contained in the taxonomy argument.
+ *
</ins><span class="cx">  * @since 2.5.0
</span><span class="cx">  * @uses $wp_query
</span><span class="cx">  *
</span><del>- * @param string|array $slug Optional. Slug or slugs to check in current query.
</del><ins>+ * @param string|array $taxonomy Optional. Taxonomy slug or slugs to check in current query.
+ * @param int|array|string $term. Optional. A single or array of, The term's ID, Name or Slug
</ins><span class="cx">  * @return bool
</span><span class="cx">  */
</span><del>-function is_tax( $slug = '' ) {
-        global $wp_query;
</del><ins>+function is_tax( $taxonomy = '', $term = '' ) {
+        global $wp_query, $wp_taxonomies;
</ins><span class="cx"> 
</span><del>-        if ( !$wp_query-&gt;is_tax )
</del><ins>+        $queried_object = $wp_query-&gt;get_queried_object();
+        $tax_array = array_intersect(array_keys($wp_taxonomies), (array) $taxonomy);
+        $term_array = (array) $term;
+
+        if ( ! ( $wp_query-&gt;is_tax || $wp_query-&gt;is_category || $wp_query-&gt;is_tag ) )
</ins><span class="cx">                 return false;
</span><span class="cx"> 
</span><del>-        if ( empty($slug) )
</del><ins>+        if ( empty( $taxonomy ) )
</ins><span class="cx">                 return true;
</span><span class="cx"> 
</span><del>-        return in_array( get_query_var('taxonomy'), (array) $slug );
</del><ins>+        if ( empty( $term ) ) // Only a Taxonomy provided
+                return isset($queried_object-&gt;taxonomy) &amp;&amp; count( $tax_array ) &amp;&amp; in_array($queried_object-&gt;taxonomy, $tax_array);
+
+        return isset($queried_object-&gt;term_id) &amp;&amp; 
+                        count(array_intersect(
+                                array($queried_object-&gt;term_id, $queried_object-&gt;name, $queried_object-&gt;slug), 
+                                $term_array
+                        ));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span></span></pre>
</div>
</div>

</body>
</html>