<?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>Adrenalin &#187; PHP and MySQL</title>
	<atom:link href="http://a.drenal.in/category/programming/php-and-mysql/feed" rel="self" type="application/rss+xml" />
	<link>http://a.drenal.in</link>
	<description>Stimulants on the Internet, Programming and Photography</description>
	<lastBuildDate>Thu, 29 Oct 2009 15:02:36 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Clean up Out-dated Custom Field Data in WordPress Post</title>
		<link>http://a.drenal.in/programming/php-and-mysql/clean-up-out-dated-custom-field-data-in-wordpress-post.html</link>
		<comments>http://a.drenal.in/programming/php-and-mysql/clean-up-out-dated-custom-field-data-in-wordpress-post.html#comments</comments>
		<pubDate>Tue, 25 Nov 2008 07:49:14 +0000</pubDate>
		<dc:creator>Keefe Dunn</dc:creator>
				<category><![CDATA[PHP and MySQL]]></category>
		<category><![CDATA[clean up]]></category>
		<category><![CDATA[custom field]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://enl.iten.me/programming/php-and-mysql/clean-up-out-dated-custom-field-data-in-wordpress-post.html</guid>
		<description><![CDATA[ If you ever used a magazine-style theme, you must be familiar with the concept &#34;custom field&#34;. In essence, it's a key-value pair storing post data about what additional info to display in a specific page. In most cases, we take advantage of custom field to display an image related to the post.
Problems We Have
There [...]]]></description>
			<content:encoded><![CDATA[<p><img style="display: inline; margin-left: 0px; margin-right: 10px" src="http://img151.imageshack.us/img151/2726/cleanupth1.jpg" align="left" /> If you ever used a magazine-style theme, you must be familiar with the concept &quot;custom field&quot;. In essence, it's a key-value pair storing post data about what additional info to display in a specific page. In most cases, we take advantage of custom field to display an image related to the post.</p>
<p><strong>Problems We Have</strong></p>
<p>There are two major problems with this.</p>
<p>Firstly, the name of the keys differ among various themes, as a result of which, some custom field data turn to be outmoded when you change the theme.</p>
<p>Secondly, while a post is becoming out-dated as time goes, there's little chance for that post to be displayed in any page at all. And the custom field data belonging to that post is getting redundant as well.</p>
<p><strong>Solutions We Get</strong></p>
<p>For the first question, the answer is in the following steps:</p>
<p>Step 1: Go to WordPress admin page and edit whichever post contains that custom field key, then write down the name of the key. In the example below, it is &quot;image&quot;.</p>
<p><img style="display: block; float: none; margin-left: auto; margin-right: auto" src="http://img384.imageshack.us/img384/3514/customfieldsamplesw8.jpg" /></p>
<p>Step 2: Go to you phpMyAdmin page and choose the WordPress database from the left column, then click the SQL query window icon.</p>
<p><img style="display: block; float: none; margin-left: auto; margin-right: auto" src="http://img219.imageshack.us/img219/5619/phpmyadminan0.jpg" /> </p>
<p>Step 3: Type in following query string and &quot;GO&quot;. That's it. (Replace &quot;image&quot; with your key name.)</p>
<p class="source" style="font-family: &#39;Courier New&#39;,&#39;Consolas&#39;,&#39;Lucida Console&#39;; background-color: #cdeb8b" jquery1227597030703="2"><span class="lineno" style="color: #008000"></span><span style="color: #008000"># remove entries with &quot;image&quot; as key name</span>     <br /><span class="lineno" style="color: #008000"></span><span style="color: #0000ff">DELETE</span> <span style="color: #0000ff">FROM</span> wp_postmeta <span style="color: #0000ff">WHERE</span> meta_key = <span style="color: #a31515">'image'</span>     </p>
<p>For the second case, I'll just provide a way of thinking, instead of a solid answer. For instance, I've got five posts with custom fields to show in a specific page, then I should keep the custom fields belonging to the latest five post, and delete the rest of them. A small change of the query string above will do just fine.</p>
<p class="source" style="font-family: &#39;Courier New&#39;,&#39;Consolas&#39;,&#39;Lucida Console&#39;; background-color: #cdeb8b" jquery1227598074593="2"><span class="lineno" style="color: #008000"></span><span style="color: #008000"># get the latest post_id</span>     <br /><span class="lineno" style="color: #008000"></span><span style="color: #0000ff">SELECT</span> @idMax := MAX(post_id) <span style="color: #0000ff">FROM</span> wp_postmeta;     <br /><span class="lineno" style="color: #008000"></span><span style="color: #008000"># keep the latest five and remove the rest of them</span>     <br /><span class="lineno" style="color: #008000"></span><span style="color: #0000ff">DELETE</span> <span style="color: #0000ff">FROM</span> wp_postmeta <span style="color: #0000ff">WHERE</span> (@idMax - post_id &gt; 5) <span style="color: #0000ff">AND</span> meta_key = <span style="color: #a31515">'image'</span>     </p>
<p>NOTICE: Use the statements above at your own risk, because the value of post_id does not always increase normally.</p>
<div class="wlWriterEditableSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:e4cbbe3e-f157-489e-a2ad-43c90f63d7e9" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px">Technorati Tags: <a href="http://technorati.com/tags/wordpress" rel="tag">wordpress</a>,<a href="http://technorati.com/tags/custom+field" rel="tag">custom field</a>,<a href="http://technorati.com/tags/clean+up" rel="tag">clean up</a></div>
<img src="http://a.drenal.in/?ak_action=api_record_view&id=332&type=feed" alt="" />

<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://a.drenal.in/programming/php-and-mysql/clean-up-out-dated-custom-field-data-in-wordpress-post.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
