{"id":2382402,"date":"2011-11-04T12:11:08","date_gmt":"2011-11-04T12:11:08","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/plugin-page-tagger\/"},"modified":"2016-08-20T03:16:34","modified_gmt":"2016-08-20T03:16:34","slug":"plugin-page-tagger","status":"closed","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/plugin-page-tagger\/","title":{"rendered":"[Plugin: Page Tagger] Bug with custom post types which have tag support"},"content":{"rendered":"<p>This plugin works fine &#8211; if you only use posts and pages.<\/p>\n<p>If you also use a custom post type with tag-support (taxonomy: <code>post_tag<\/code>), the plugin breaks the process of updating the correct count of tags in database so other functionalities, e.g. Tag Clouds, get unexpected and wrong results.<\/p>\n<p>The plugin overrides the default tag count update callback <code>_update_post_term_count<\/code> of taxonomy <code>post_tag<\/code> with a hardcoded sql-statement with only post types <code>post<\/code> and <code>page<\/code> so any other post type will not be updated.<\/p>\n<p>Fix for Page Tagger 0.3.6, at end of file <em>page-tagger-class.php<\/em><\/p>\n<p>Old, only 2 hardcoded post_types:<\/p>\n<pre><code>function _update_post_term_count( $terms )\n\t{\n\t\tglobal $wpdb;\n\t\tforeach ( (array) $terms as $term ) {\n\t\t\t$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_type = &#039;post&#039; OR post_type = &#039;page&#039;) AND term_taxonomy_id = %d&quot;, $term ) );\n\t\t\t$wpdb-&gt;update( $wpdb-&gt;term_taxonomy, compact( &#039;count&#039; ), array( &#039;term_taxonomy_id&#039; =&gt; $term ) );\n\t\t}\n\t}<\/code><\/pre>\n<p>New, add also custom post types to SELECT statement:<\/p>\n<pre><code>function _update_post_term_count( $terms )\n\t{\n\t\tglobal $wpdb;\n\t\tforeach ( (array) $terms as $term ) {\n\t\t\t$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_type = &#039;post&#039; OR post_type = &#039;page&#039;&quot; . $this-&gt;_get_custom_post_types_sql() . &quot;) AND term_taxonomy_id = %d&quot;, $term ) );\n\t\t\t$wpdb-&gt;update( $wpdb-&gt;term_taxonomy, compact( &#039;count&#039; ), array( &#039;term_taxonomy_id&#039; =&gt; $term ) );\n\t\t}\n\t}\n\/* Hack for custom post types support *\/\nfunction _get_custom_post_types_sql() {\n\t\t$sql = &#039;&#039;;\n\t\t$cpt_arr = array();\n\t\t$args = array(\n\t\t\t&#039;public&#039;   =&gt; true,\n\t\t\t&#039;_builtin&#039; =&gt; false,\n\t\t\t&#039;taxonomies&#039; =&gt; array(&#039;post_tag&#039;) \/\/ taxonomies actually not used, bug wp 3.2.1\n\t\t);\n\t\t$post_types = get_post_types($args, &#039;names&#039;);\n\t\tforeach ($post_types as $post_type ) {\n\t\t\t$cpt_arr[] = &quot;post_type = &#039;$post_type&#039;&quot;;\n\t\t}\n\t\tif ($cpt_arr) {\n\t\t\t$sql = &#039; OR &#039; . implode(&#039; OR &#039;, $cpt_arr);\n\t\t}\n\t\treturn $sql;\n\t}<\/code><\/pre>\n<p>https:\/\/wordpress.org\/extend\/plugins\/page-tagger\/<\/p>\n","protected":false},"template":"","class_list":["post-2382402","topic","type-topic","status-closed","hentry","topic-tag-custom-post-type"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/2382402","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/2382402\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=2382402"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}