Tuesday - October 05, 2004
fixed error editing comments in WordPress

I had some links to my site in comments using the old permalinks format and I decided to update them to the new format. When I tried however, I got a MySQL error. I looked on WordPress Support and found the issue but no one had provided a fix. Here’s one that worked for me.

Add the following line:

$content = $wpdb->escape($content);

right below line 694, which should be

$content = format_to_post($content);

in WordPress version 1.2 in wordpress/wp-admin/post.php

I posted a response there as well but wanted to help people to avoid the frustration of not being able to edit comments.







converting links from MT to WordPress

I had over 1,000 posts in Movable Type that were archived individually, by month and by category. When I switched to WordPress I changed the format of the permanent links to include the date and title instead of the non-portable post ID (which, by the way, MT does not include when you export your blog so your permanent links won’t work if you export and import your blog through MT either).

I was concerned that I wouldn’t be able to get those old URLs to forward to WordPress but in the end it wasn’t all that difficult. The easiest was the monthly archive. It used to be “/archive/year_month.html” so I just added a line in the .htaccess to change it to “/archives/year/month” and I was done.

RewriteRule ^archive/([0-9]{4})_([0-9]{2}).html$ /index.php?year=$1&monthnum=$2

The category names would have been easy except that Movable Type uses underscores and WordPress uses hyphens. I already use PHP on my site, so I was able to take advantage of that fact. I found the code in WordPress that converts category names into what is used in the URL and put it in the category archive template. The code generates the new URL to use and forwards the user. This code must go at the very top of the template.

$title = strtolower( "<$MTArchiveTitle$>" );
$title = preg_replace('/&.+?;/', '', $title); // kill entities
$title = preg_replace('/[^a-z0-9 _-]/', '', $title);
$title = preg_replace('/s+/', ' ', $title);
$title = str_replace(' ', '-', $title);
$title = preg_replace('|-+|', '-', $title);
$title = trim($title, '-');
Header( "Location: /archives/category/$title" );

I did pretty much the same thing with Individual archives except I needed to add the date in addition to converting the title to the post slug. Here is the code I put at the top of the Individual archive template.

$title = strtolower( "<$MTArchiveTitle$>" );
$title = preg_replace('/&.+?;/', '', $title); // kill entities
$title = preg_replace('/[^a-z0-9 _-]/', '', $title);
$title = preg_replace('/s+/', ' ', $title);
$title = str_replace(' ', '-', $title);
$title = preg_replace('|-+|', '-', $title);
$title = trim($title, '-');
<MTDateHeader>
$date = "<$MTEntryDate format="%Y/%m/%d"$>";
</MTDateHeader>
Header( "Location: /archives/$date/$title" );

The .htaccess change is a little less ideal because it leaves the old URL. The other two changes change the URL in the user’s browser to the new link. The advantage however is that I was able to remove the category archives. I have to leave the rest of the files there because they contain the information needed to forward to the new URL.







# of readers
- home
meta
comics
news links
other links

about me
blog archives
docs
entertainment
experiences
funny lists
humor
intellectual
interests
mefi
music
opinions
photos
web designs
tools
webmaster help

Sign up
Enter your e-mail address to be notified of new posts



Search blog archives

Calendar
October 2004
S M T W T F S
« Sep   Nov »
 12
3456789
10111213141516
17181920212223
24252627282930
31  



Random quote
(View all quotes)
"There is no virtue so great as to be safe from temptation..."










Licensed under Creative Commons
(?) Choose theme:  X X X X X X


W3CCSS
Loaded in 0.1592 seconds