<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Push cx &#187; MySQL</title>
	<atom:link href="http://push.cx/tag/mysql/feed" rel="self" type="application/rss+xml" />
	<link>http://push.cx</link>
	<description>A traveling geek&#039;s blog on development, games, and the web</description>
	<lastBuildDate>Thu, 19 Apr 2012 20:39:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Turning WordPress Categories Into Tags</title>
		<link>http://push.cx/2008/turning-wordpress-categories-into-tags</link>
		<comments>http://push.cx/2008/turning-wordpress-categories-into-tags#comments</comments>
		<pubDate>Thu, 17 Apr 2008 14:05:39 +0000</pubDate>
		<dc:creator>Peter Harkins</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[automation]]></category>
		<category><![CDATA[insert into select]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://push.cx/?p=310</guid>
		<description><![CDATA[I recently updated this WordPress install from 2.2.something to 2.5 and noticed that it now supports tags instead of just categories. I had been using categories as tags, but I&#8217;d rather built-in tags than fake it anymore. I didn&#8217;t want to manually retag a couple hundred posts with ~200 tags, so I wrote some SQL [...]]]></description>
			<content:encoded><![CDATA[<p>
I recently updated this WordPress install from 2.2.something to 2.5 and noticed that it now supports tags instead of just categories. I had been using categories as tags, but I&#8217;d rather built-in tags than fake it anymore. I didn&#8217;t want to manually retag a couple hundred posts with ~200 tags, so I wrote some SQL to do it for me. If you&#8217;re in the same boat
</p>

<p>
<strong>Warning</strong>: This could break and completely mess up your categories and tags. I&#8217;m only promising this worked for me on my install for now (who knows, maybe I updated things wrong and huge problems will occur a month from now). Use caution. I take no responsibility.
</p>

<pre>&nbsp;
<span style="color: #808080; font-style: italic;"># create tags for every category</span>
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> wp_term_taxonomy <span style="color: #66cc66;">&#40;</span>term_id, taxonomy<span style="color: #66cc66;">&#41;</span>
    <span style="color: #993333; font-weight: bold;">SELECT</span> term_id, <span style="color: #ff0000;">"post_tag"</span>
    <span style="color: #993333; font-weight: bold;">FROM</span> wp_term_taxonomy
    <span style="color: #993333; font-weight: bold;">WHERE</span> taxonomy = <span style="color: #ff0000;">'category'</span>;
&nbsp;
<span style="color: #808080; font-style: italic;"># copy category-post relationships to tag-post relationships</span>
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> wp_term_relationships <span style="color: #66cc66;">&#40;</span>object_id, term_taxonomy_id<span style="color: #66cc66;">&#41;</span> 
    <span style="color: #993333; font-weight: bold;">SELECT</span> 
        object_id, 
        <span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> i.term_taxonomy_id
         <span style="color: #993333; font-weight: bold;">FROM</span> wp_term_taxonomy i
         <span style="color: #993333; font-weight: bold;">WHERE</span>
             taxonomy = <span style="color: #ff0000;">'post_tag'</span> <span style="color: #993333; font-weight: bold;">AND</span> 
             i.term_id = wp_term_taxonomy.term_id<span style="color: #66cc66;">&#41;</span>
    <span style="color: #993333; font-weight: bold;">FROM</span> wp_term_relationships 
    <span style="color: #993333; font-weight: bold;">JOIN</span> wp_term_taxonomy <span style="color: #993333; font-weight: bold;">ON</span> 
        wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id 
    <span style="color: #993333; font-weight: bold;">WHERE</span> taxonomy = <span style="color: #ff0000;">'category'</span>;
&nbsp;
<span style="color: #808080; font-style: italic;"># update tag count cache</span>
<span style="color: #993333; font-weight: bold;">UPDATE</span> wp_term_taxonomy 
    <span style="color: #993333; font-weight: bold;">SET</span> count = <span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> count<span style="color: #66cc66;">&#40;</span>*<span style="color: #66cc66;">&#41;</span>
        <span style="color: #993333; font-weight: bold;">FROM</span> wp_term_relationships
        <span style="color: #993333; font-weight: bold;">WHERE</span> wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;"># remove all categories and category-post relationships</span>
<span style="color: #993333; font-weight: bold;">DELETE</span> <span style="color: #993333; font-weight: bold;">FROM</span> wp_term_taxonomy <span style="color: #993333; font-weight: bold;">WHERE</span> taxonomy = <span style="color: #ff0000;">'category'</span>;
<span style="color: #993333; font-weight: bold;">DELETE</span> <span style="color: #993333; font-weight: bold;">FROM</span> wp_term_relationships 
    <span style="color: #993333; font-weight: bold;">WHERE</span> term_taxonomy_id <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> term_taxonomy_id <span style="color: #993333; font-weight: bold;">FROM</span> wp_term_taxonomy<span style="color: #66cc66;">&#41;</span>;</pre>

<p>
The <kbd>INSERT INTO ... SELECT</kbd> was a fun little query to write with its subselect. After running this, I just had to create and apply categories to my posts (I&#8217;m going with <a href="http://push.cx/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=L2NhdGVnb3J5L2Jpeg==">Biz</a>, <a href="http://push.cx/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=L2NhdGVnb3J5L2NvZGU=">Code</a>, <a href="http://push.cx/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=L2NhdGVnb3J5L2dhbWVz">Games</a>, and <a href="http://push.cx/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=L2NhdGVnb3J5L2xpZmU=">Life</a> for now) and update my templates.
</p> <img src="http://push.cx/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=310" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://push.cx/2008/turning-wordpress-categories-into-tags/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

