<!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>[13625] trunk/wp-includes/taxonomy.php:
  Add custom post_type support to _update_post_term_coun().</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/13625">13625</a></dd>
<dt>Author</dt> <dd>dd32</dd>
<dt>Date</dt> <dd>2010-03-09 10:48:18 +0000 (Tue, 09 Mar 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>Add custom post_type support to _update_post_term_coun(). Props momo360modena. Fixes <a href="http://trac.wordpress.org/ticket/12348">#12348</a></pre>

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

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpincludestaxonomyphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/taxonomy.php (13624 => 13625)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/taxonomy.php        2010-03-09 10:23:03 UTC (rev 13624)
+++ trunk/wp-includes/taxonomy.php        2010-03-09 10:48:18 UTC (rev 13625)
</span><span class="lines">@@ -1856,7 +1856,7 @@
</span><span class="cx">         do_action( 'edited_terms', $term_id );
</span><span class="cx"> 
</span><span class="cx">         $tt_id = $wpdb-&gt;get_var( $wpdb-&gt;prepare( &quot;SELECT tt.term_taxonomy_id FROM $wpdb-&gt;term_taxonomy AS tt INNER JOIN $wpdb-&gt;terms AS t ON tt.term_id = t.term_id WHERE tt.taxonomy = %s AND t.term_id = %d&quot;, $taxonomy, $term_id) );
</span><del>-        do_action( 'edit_term_taxonomy', $tt_id );
</del><ins>+        do_action( 'edit_term_taxonomy', $tt_id, $taxonomy );
</ins><span class="cx">         $wpdb-&gt;update( $wpdb-&gt;term_taxonomy, compact( 'term_id', 'taxonomy', 'description', 'parent' ), array( 'term_taxonomy_id' =&gt; $tt_id ) );
</span><span class="cx">         do_action( 'edited_term_taxonomy', $tt_id );
</span><span class="cx"> 
</span><span class="lines">@@ -1954,14 +1954,14 @@
</span><span class="cx"> 
</span><span class="cx">         $taxonomy = get_taxonomy($taxonomy);
</span><span class="cx">         if ( !empty($taxonomy-&gt;update_count_callback) ) {
</span><del>-                call_user_func($taxonomy-&gt;update_count_callback, $terms);
</del><ins>+                call_user_func($taxonomy-&gt;update_count_callback, $terms, $taxonomy);
</ins><span class="cx">         } else {
</span><span class="cx">                 // Default count updater
</span><span class="cx">                 foreach ( (array) $terms as $term) {
</span><span class="cx">                         $count = $wpdb-&gt;get_var( $wpdb-&gt;prepare( &quot;SELECT COUNT(*) FROM $wpdb-&gt;term_relationships WHERE term_taxonomy_id = %d&quot;, $term) );
</span><del>-                        do_action( 'edit_term_taxonomy', $term );
</del><ins>+                        do_action( 'edit_term_taxonomy', $term, $taxonomy );
</ins><span class="cx">                         $wpdb-&gt;update( $wpdb-&gt;term_taxonomy, compact( 'count' ), array( 'term_taxonomy_id' =&gt; $term ) );
</span><del>-                        do_action( 'edited_term_taxonomy', $term );
</del><ins>+                        do_action( 'edited_term_taxonomy', $term, $taxonomy );
</ins><span class="cx">                 }
</span><span class="cx"> 
</span><span class="cx">         }
</span><span class="lines">@@ -2336,7 +2336,7 @@
</span><span class="cx"> //
</span><span class="cx"> 
</span><span class="cx"> /**
</span><del>- * Will update term count based on posts.
</del><ins>+ * Will update term count based on object types of the current taxonomy.
</ins><span class="cx">  *
</span><span class="cx">  * Private function for the default callback for post_tag and category
</span><span class="cx">  * taxonomies.
</span><span class="lines">@@ -2348,15 +2348,19 @@
</span><span class="cx">  * @uses $wpdb
</span><span class="cx">  *
</span><span class="cx">  * @param array $terms List of Term taxonomy IDs
</span><ins>+ * @param object $taxonomy Current taxonomy object of terms
</ins><span class="cx">  */
</span><del>-function _update_post_term_count( $terms ) {
</del><ins>+function _update_post_term_count( $terms, $taxonomy ) {
</ins><span class="cx">         global $wpdb;
</span><span class="cx"> 
</span><ins>+        $object_types = is_array($taxonomy-&gt;object_type) ? $taxonomy-&gt;object_type : array($taxonomy-&gt;object_type);
+        $object_types = esc_sql($object_types);
+
</ins><span class="cx">         foreach ( (array) $terms as $term ) {
</span><del>-                $count = $wpdb-&gt;get_var( $wpdb-&gt;prepare( &quot;SELECT COUNT(*) FROM $wpdb-&gt;term_relationships, $wpdb-&gt;posts WHERE $wpdb-&gt;posts.ID = $wpdb-&gt;term_relationships.object_id AND post_status = 'publish' AND post_type = 'post' AND term_taxonomy_id = %d&quot;, $term ) );
-                do_action( 'edit_term_taxonomy', $term );
</del><ins>+                $count = $wpdb-&gt;get_var( $wpdb-&gt;prepare( &quot;SELECT COUNT(*) FROM $wpdb-&gt;term_relationships, $wpdb-&gt;posts WHERE $wpdb-&gt;posts.ID = $wpdb-&gt;term_relationships.object_id AND post_status = 'publish' AND post_type IN ('&quot; . implode(&quot;', '&quot;, $object_types) . &quot;') AND term_taxonomy_id = %d&quot;, $term ) );
+                do_action( 'edit_term_taxonomy', $term, $taxonomy );
</ins><span class="cx">                 $wpdb-&gt;update( $wpdb-&gt;term_taxonomy, compact( 'count' ), array( 'term_taxonomy_id' =&gt; $term ) );
</span><del>-                do_action( 'edited_term_taxonomy', $term );
</del><ins>+                do_action( 'edited_term_taxonomy', $term, $taxonomy );
</ins><span class="cx">         }
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>