<?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>iamtgc &#187; Wordpress</title>
	<atom:link href="http://iamtgc.com/category/wordpress/feed/" rel="self" type="application/rss+xml" />
	<link>http://iamtgc.com</link>
	<description></description>
	<lastBuildDate>Wed, 21 Jul 2010 12:13:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>How to Fix or Remove Uncooperative Widgets in&#160;WordPress</title>
		<link>http://iamtgc.com/2008/12/03/how-to-fix-or-remove-uncooperative-widgets-in-wordpress/</link>
		<comments>http://iamtgc.com/2008/12/03/how-to-fix-or-remove-uncooperative-widgets-in-wordpress/#comments</comments>
		<pubDate>Wed, 03 Dec 2008 05:19:41 +0000</pubDate>
		<dc:creator>tgc</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://iamtgc.com/?p=33</guid>
		<description><![CDATA[Recently, I was working with php-code-widget to include some custom PHP code in a WordPress widget. Unfortunately, and much to my surprise, the custom code did not work flawlessly the first time and I was left staring at errors like: &#8220;Fatal error: Call to undefined function test(); in wp-content/plugins/php-code-widget /execphp.php(37): eval()&#8217;d code on line 1&#8243;. [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, I was working with <a href="http://wordpress.org/extend/plugins/php-code-widget/">php-code-widget</a> to include some custom PHP code in a WordPress widget.  </p>
<p>Unfortunately, and much to my surprise, the custom code did not work flawlessly the first time and I was left staring at errors like:</p>
<p><strong>&#8220;Fatal error: Call to undefined function test(); in wp-content/plugins/php-code-widget /execphp.php(37): eval()&#8217;d code on line 1&#8243;.</strong><br />
<span id="more-33"></span><br />
Unfortunately, as this error shows up in the dashboard where I would normally edit the widgets content, this is not as straight forward to fix as one would hope.  So&#8230; after diving into the database and some trial and error I found that the widgets reside in the wp_options table, as this table is quite large, and contains more than just widget information, I had to narrow down what I was looking for.  I ended up with this query:</p>
<p><code>mysql&gt; select option_name from wp_options where option_name like 'widget_%';
+------------------------+
| option_name            |
+------------------------+
| widget_akismet         |
| widget_archives        |
| widget_calendar        |
| widget_categories      |
| widget_execphp         |
| widget_meta            |
| widget_pages           |
| widget_recent_comments |
| widget_recent_entries  |
| widget_rss             |
| widget_tag_cloud       |
| widget_text            |
+------------------------+</code></p>
<p>In this case, it is content in the php-code-widget that is causing our errors, as there is no widget_php-code-widget, it seems that the widget_execphp is the next closest thing.  So let&#8217;s inspect the widget_execphp entry.</p>
<p><code>mysql&gt; select * from wp_options where option_name='widget_execphp';
+-----------+---------+----------------+-----------------------------------------------------------------------------------+----------+
| option_id | blog_id | option_name    | option_value                                                                      | autoload |
+-----------+---------+----------------+-----------------------------------------------------------------------------------+----------+
|       347 |       0 | widget_execphp | a:1:{i:291302011;a:2:{s:5:"title";s:4:"Test";s:4:"text";s:16:"&lt;?php test();?&gt;";}} | yes      |
+-----------+---------+----------------+-----------------------------------------------------------------------------------+----------+</code></p>
<p>Bingo&#8230; here we can see the code that was entered into the widget.  In this case the test() function does not exist.</p>
<p>The first, and arguably the simplest option is to simply delete the entry,  we delete it using the option_id value we obtained above.  The option_id value is also used later in the article, in the event you chose to update the entry as opposed to removing it.<br />
<code>mysql&gt; delete from wp_options where option_id=347;
Query OK, 1 row affected (0.29 sec)</code></p>
<p>At this point you can simply go back into the dashboard and recreate your widget, more careful not to include non existent functions this time.  But that would be too easy, a more interesting  alternative is to modify the existing entry.</p>
<p><code>mysql&gt; update wp_options set option_value = "a:1:{i:291302011;a:2:{s:5:\"title\";s:4:\"Test\";s:4:\"text\";s:20:\"&lt;?php new_test(); ?&gt;\";}}" where option_id=347;                   
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0</code></p>
<p>Let&#8217;s look at this more closely, the above query updates option_value to:<br />
<br />
a:1:{i:291302011;a:2:{s:5:&#8221;title&#8221;;s:4:&#8221;Test&#8221;;s:4:&#8221;text&#8221;;<strong>s:20:&#8221;&lt;?php new_test(); ?&gt;&#8221;</strong>;}}</p>
<p>If you notice, two things have changed from the previous option_value value.  </p>
<p>The first change is to the string length variable, represented by <i>s</i>, which precedes the string.  In our example s:16 becomes s:20.  More simply put <strong>&lt;?php test(); ?&gt;</strong> (16 characters in length) becomes <strong>&lt;?php new_test(); ?&gt;</strong> (20 characters in length).</p>
<p>The necessary changes is to the string itself, and probably the reason you are getting the undesirable behavior in the first place, is left up to the reader.  It is my hope that this sets you in the right direction.</p>
]]></content:encoded>
			<wfw:commentRss>http://iamtgc.com/2008/12/03/how-to-fix-or-remove-uncooperative-widgets-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Moving Comments in&#160;WordPress</title>
		<link>http://iamtgc.com/2008/07/23/moving-comments-in-wordpress/</link>
		<comments>http://iamtgc.com/2008/07/23/moving-comments-in-wordpress/#comments</comments>
		<pubDate>Thu, 24 Jul 2008 01:10:10 +0000</pubDate>
		<dc:creator>tgc</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://iamtgc.com/?p=23</guid>
		<description><![CDATA[I find that often times comments on blogs are left for the wrong post. Whether by mistake, laziness, carelessness or otherwise on the part of the commenter, this can lead to potentially pertinent information being in the wrong place. Whatever the cause, the following article will describe in detail how you can easily manipulate your [...]]]></description>
			<content:encoded><![CDATA[<p>I find that often times comments on blogs are left for the wrong post.  Whether by mistake, laziness, carelessness or otherwise on the part of the commenter, this can lead to potentially pertinent information being in the wrong place. </p>
<p>Whatever the cause, the following article will describe in detail how you can easily manipulate your wordpress database to move the misplaced comments you have to the post they belong under.<br />  <span id="more-23"></span><br />
This article will accomplish this by using the command line <i>mysql</i> utility.  Depending on where you have your wordpress blog hosted, you may not have access to the database at all, or if you do you may have to access it using a tool such as <a href="http://www.phpmyadmin.net/home_page/index.php">phpmyadmin</a>.</p>
<p>But before I get started, here is a list of what you will need to complete this process:<br />
* mysql username<br />
* mysql password<br />
* mysql wordpress database name</p>
<p>First you&#8217;ll need to connect to mysql and select your database<br />
<code>$ mysql -u wordpress -p
Enter Password: ********

mysql&gt; use my-wordpress-database;
Database changed
mysql&gt;</code></p>
<p>Now, there are two tables that are of primary interest, <b>wp_posts</b> and <b>wp_comments</b>.<br />
Let&#8217;s start with <b>wp_posts</b>, the columns of interest are <i>ID</i> and <i>post_title</i>.<br />
<code>mysql&gt;select ID, post_title from wp_posts;
+----+------------------------------------------------+
| ID | post_title                                     |
+----+------------------------------------------------+
|  4 | Bob Dylan                                      |
|  6 | Johnny Cash                                    |
+----+------------------------------------------------+</code></p>
<p>Now let&#8217;s look at the comments that have been left, they reside in the <b>wp-comments</b> table.<br />
Here, the columns of interest are <i>comment_ID</i>, <i>comment_post_ID</i>, and <i>comment_content</i>.<br />
<code>mysql&gt;select comment_ID, comment_post_ID, comment_content from wp_comments;
+------------+-----------------+-------------------------------------------+
| comment_ID | comment_post_ID | comment_content                           |
+------------+-----------------+-------------------------------------------+
|          1 |               4 | I really like Bob Dylan, nice article     |
|          2 |               4 | Johnny Cash is the best                   |
|          3 |               6 | Johnny Cash the man in black              |
+------------+-----------------+-------------------------------------------+</code></p>
<p>Note, in <b>wp_comments</b>, <i>comment_post_ID</i> ties in to <b>wp_posts</b> <i>ID</i>.  So that means there are two comments for the Bob Dylan post, and one comment for the Johnny Cash post.</p>
<p>But wait&#8230;</p>
<p>The second comment, with <i>comment_ID</i> 2 looks like it is supposed to be a comment for the Johnny Cash post.  Let&#8217;s see how we can move it.<br />
<code>mysql&gt; update wp_comments set comment_post_ID=6 where comment_ID=2;
Query OK, 1 row affected (0.02 sec)
Rows matched: 1  Changed: 1  Warnings: 0</code><br />
and verify that it was moved<br />
<code>mysql&gt;select comment_ID, comment_post_ID, comment_content from wp_comments;
+------------+-----------------+-------------------------------------------+
| comment_ID | comment_post_ID | comment_content                           |
+------------+-----------------+-------------------------------------------+
|          1 |               4 | I really like Bob Dylan, nice article     |
|          2 |               6 | Johnny Cash is the best                   |
|          3 |               6 | Johnny Cash the man in black              |
+------------+-----------------+-------------------------------------------+</code></p>
<p>Good, the comment was successfully moved, but there is still a problem.<br />
<code>mysql&gt; select comment_count from wp_posts where ID=6;
+---------------+
| comment_count |
+---------------+
|             1 |
+---------------+</code><br />
There are supposed to be two comments, so let&#8217;s update the comment_count for both the post that the comment was moved from, and where it was moved to.<br />
<code>mysql&gt; update wp_posts set comment_count=2 where ID=6;

mysql&gt; select comment_count from wp_posts where ID=4;
+---------------+
| comment_count |
+---------------+
|             2 |
+---------------+

mysql&gt; update wp_posts set comment_count=1 where ID=4;

mysql&gt; select post_title, comment_count from wp_posts where ID in (4,6);
+------------------------------+---------------+
| post_title                   | comment_count |
+------------------------------+---------------+
| Bob Dylan                    |             1 |
| Johnny Cash                  |             2 |
+------------------------------+---------------+</code><br />
And that&#8217;s it.  Now your comments are moved and all of the counters have been updated to reflect the moved comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://iamtgc.com/2008/07/23/moving-comments-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Definitive Guide to WordPress&#160;Rewrites</title>
		<link>http://iamtgc.com/2007/06/02/definitive-guide-to-wordpress-rewrites/</link>
		<comments>http://iamtgc.com/2007/06/02/definitive-guide-to-wordpress-rewrites/#comments</comments>
		<pubDate>Sun, 03 Jun 2007 03:29:38 +0000</pubDate>
		<dc:creator>tgc</dc:creator>
				<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://iamtgc.com/2007/06/02/definitive-guide-to-wordpress-rewrites/</guid>
		<description><![CDATA[There are many tutorials that exist on implementing rewrites and redirects in wordpress. However all of the ones I&#8217;ve found have fallen short and the most applicable advice is buried deep within some indirectly related forum. What I aim to do is address the most common questions and pitfalls people run into when modifying .htaccess [...]]]></description>
			<content:encoded><![CDATA[<p>There are many tutorials that exist on implementing rewrites and redirects in wordpress.  However all of the ones I&#8217;ve found have fallen short and the most applicable advice is buried deep within some indirectly related forum.  What I aim to do is address the most common questions and pitfalls people run into when modifying .htaccess and implementing rewrites in wordpress.</p>
<p>There are many reasons why you may need to put a redirect on your blog, perhaps one of the most common is when content changes or is moved; maybe you&#8217;re migrating an existing web page or blog into wordpress.<br />
<span id="more-5"></span><br />
So let&#8217;s look at the migration scenario, we have a number of files which we want to move into wordpress posts and pages and since we are the authority on the modern stone age family, countless Bedrock fans link to us.  Since we would like to maintain the integrity of these links, we look to htaccess and mod_rewrite to rewrite incoming requests for the old content hierarchy to our wordpress hierarchy.</p>
<p>Before we go futher, here is a look at the default wordpress .htaccess file, this file should reside in the wordpress root directory.<br />
<code># BEGIN WordPress
&lt;IfModule mod_rewrite.c&gt;
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
&lt;/IfModule&gt;
# END WordPress</code></p>
<p>Now, let&#8217;s consider the files (links) which we wish to maintain.  Some are static html and others dynamic php which take arguments to determine the content.<br />
<code>/about.html
/bedrock.html
/bio.php?character=fred
/bio.php?character=wilma
/bio.php?character=pebbles
/bio.php?character=dino</code></p>
<p>No problem, let&#8217;s knock about.html first, the mod_rewrite rule should look like this<br />
<code>RewriteRule ^about\.html$ /about [R=301,L]</code></p>
<p>This rule is fairly straight forward, but requires some knowledge of regular expressions, let&#8217;s break it down.  <b>RewriteRule</b> is the configuration directive.  <b>^about\.html$</b> is where it starts to look confusing.</p>
<p>The <b>^</b> indicates the beginning of the request, without this a request for <b>whatabout.html</b> or <b>nothingabout.html</b> would match the same as a request for <b>about.html</b> would.</p>
<p>Much like <b>^</b> does for the beginning of the request, <b>$</b>marks the end of the request.  Without <b>$</b> requests such as <b>about.html.backup</b> would match the same as <b>about.html</b>.</p>
<p>Finally, <b>.</b> is a special character in regular expressions which means match any character, so we escape it with a backslash to represent a literal period.  Without escaping it, you would match requests such as <b>aboutahtml</b>.</p>
<p>Returning to our rewrite rule, <b>/about</b> is what we are rewriting <b>about.html</b> with.</p>
<p><b>[R=301,L]</b> are the flags you&#8217;re passing the rewrite rule.  <b>R</b> means redirect and <b>301</b> is a redirect code for <i>permanent redirect</i>, which is perfect in our scenario. <b>L</b> means this is the last rule, if we match, apply the rewrite and stop evaluating rules.</p>
<p>Now, let&#8217;s address /bio.php?character=fred, while you might logically try<br />
<code># This does not work
RewriteRule ^bio.php\?character=fred$ /fred [R=301,L]</code></p>
<p>It does not work and can lead to hours of frustration, the mod_rewrite rule should look like this<br />
<code># Working Rewrite
RewriteCond %{query_string} ^character=fred$
RewriteRule ^bio\.php$ /fred? [R=301,L]</code></p>
<p>We&#8217;ve introduced a new configuration directive, <b>RewriteCond</b>.  As the name suggests, this directive allows you to pass conditions on which to assess the rewrite rule.  In our scenario we want to assess <b>RewriteRule</b> if the query string, represented by <b>%{query_string}</b> is <b>character=fred</b>.</p>
<p>The <b>RewriteRule</b> should look familiar, as <b>RewriteCond</b> is already handling the arguments for the php script the only real difference is the trailing <b>?</b> on the rewrite, without the trailing <b>?</b>, when <b>/bio.php?character=fred</b> is requested, you would end up with <b>/fred?character=fred</b> after the rewrite.  While this may be desirable in some scenarios, this is not what we want.</p>
<p>With these two scenarios addressed, we can complete our modification to .htaccess, after you&#8217;ve added the rewrite rules, your .htaccess should resemble the below.<br />
<code># BEGIN WordPress
&lt;IfModule mod_rewrite.c&gt;
RewriteEngine On
RewriteBase /
RewriteRule ^about.html$ /about [R=301,L]
RewriteRule ^bedrock.html$ /bedrock [R=301,L]
RewriteCond %{query_string} ^character=fred$
RewriteRule ^bio\.php$ /fred? [R=301,L]
RewriteCond %{query_string} ^character=wilma$
RewriteRule ^bio\.php$ /wilma? [R=301,L]
RewriteCond %{query_string} ^character=pebbles$
RewriteRule ^bio\.php$ /pebbles? [R=301,L]
RewriteCond %{query_string} ^character=dino$
RewriteRule ^bio\.php$ /dino? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
&lt;/IfModule&gt;
# END WordPress</code></p>
]]></content:encoded>
			<wfw:commentRss>http://iamtgc.com/2007/06/02/definitive-guide-to-wordpress-rewrites/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
