Fixed WordPress Database Error with Simple Tagging Plugin


I just downloaded the Simple Tagging 1.6 Plugin today and I got errors when I tried to convert the categories to tags on the import tags section. The following will explain the error, and how I fixed it. (I didn’t bother to do a search on this problem so someone else may have already posted a fix for it)
To be safe, I downloaded and installed the WordPress Database Backup Plugin and did a backup of the database before running the import tags function like it suggested.
So, once I got Simple Tagging installed, I clicked on the new “Tags” section then I clicked the tab labeled “Import Tags” and checked the “I’ve backed up my database” checkbox and clicked “Convert Categories to Tags.”
When I did that, it returned the follow error:

WordPress database error: [Unknown column ‘p2c.category_id’ in ‘on clause’]
SELECT cats.cat_name, p2c.post_id FROM wp_posts posts INNER JOIN wp_categories cats ON (p2c.category_id = cats.cat_id) LEFT JOIN wp_post2cat p2c ON (posts.ID = p2c.post_id) WHERE posts.post_status IN (‘publish’) AND posts.post_type <> ‘page’

To fix it, go to your simple-tagging folder (should be in the plugins folder) and look for “simpletagging.admin.php”

Look for lines 473 through 478 which looks like this:

$qry = “SELECT cats.cat_name, p2c.post_id FROM $wpdb->posts posts
INNER JOIN $wpdb->categories cats ON (p2c.category_id = cats.cat_id)
LEFT JOIN $wpdb->post2cat p2c ON (posts.ID = p2c.post_id)
WHERE posts.post_status IN (‘publish’)
AND posts.post_type <> ‘page’ “;

Replace it with:

$qry = “SELECT cats.cat_name, p2c.post_id FROM $wpdb->posts posts
LEFT JOIN $wpdb->post2cat p2c
INNER JOIN $wpdb->categories cats ON (p2c.category_id = cats.cat_id)
ON (posts.ID = p2c.post_id)
WHERE posts.post_status IN (‘publish’)
AND posts.post_type <> ‘page’ “;

Save the file. That’s it!


Leave a Reply