Wednesday, December 26, 2007

WordPress Plugin: SimpleTags Modification

WordPress SimpleTags is a WordPress plugin that will allow you to easily manage tags of your blog. However, I found some of bugs of WordPress SimpleTags, here is my modification.

1. Search terms problem:

SimpleTags use of the full text of the search, as long as the article contains the keyword matching, which can lead to large errors match, I modify it only match of the headlines.

Open file simple-tags\inc\simple-tags.admin.php, in line 1466, replace:

$search_sql = "AND ( (post_title LIKE '%{$search}%') OR (post_content LIKE '%{$search}%') )";

to:

$search_sql = "AND ( (post_title LIKE '%{$search}%') OR (post_title LIKE '%{$search}%') )";

2. Untagged only problem:

When blog have large numbers of the article, the untagged only function will return errors, I change some of original code in the SQL statement , greatly improving the efficiency of search and speed.

Open file simple-tags\inc\simple-tags.admin.php, in line 1475, replace:

$p_id_used = $wpdb->get_col("
SELECT DISTINCT term_relationships.object_id
FROM {$wpdb->term_taxonomy} term_taxonomy, {$wpdb->term_relationships} term_relationships, {$wpdb->posts} posts
WHERE term_taxonomy.taxonomy = 'post_tag'
AND term_taxonomy.term_taxonomy_id = term_relationships.term_taxonomy_id
AND term_relationships.object_id = posts.ID
AND posts.post_type = '{$type}'");
$filter_sql = 'AND ID NOT IN ("'.implode( '", "', $p_id_used ).'")';


to:

$p_id_used = "SELECT DISTINCT term_relationships.object_id
FROM {$wpdb->term_taxonomy} term_taxonomy, {$wpdb->term_relationships} term_relationships, {$wpdb->posts} posts
WHERE term_taxonomy.taxonomy = 'post_tag'
AND term_taxonomy.term_taxonomy_id = term_relationships.term_taxonomy_id
AND term_relationships.object_id = posts.ID
AND posts.post_type = '{$type}'";
$filter_sql = 'AND ID NOT IN ('.$p_id_used.')';