Skip to content

Instantly share code, notes, and snippets.

@tonykwon
Created May 23, 2012 20:44
Show Gist options
  • Save tonykwon/2777679 to your computer and use it in GitHub Desktop.
Save tonykwon/2777679 to your computer and use it in GitHub Desktop.
Media Categories Plugin - Slow Query Fix
<?php
///
// Functions Called From Init
///
public function CheckForTermOrderColumn()
{
global $wpdb;
//-- CHECK FOR term_order column ---
$query = "
SELECT COUNT(*) FROM information_schema.COLUMNS
WHERE
TABLE_SCHEMA = '" . DB_NAME . "'
AND TABLE_NAME = '$wpdb->terms'
AND COLUMN_NAME = 'term_order';
";
$row_count = $wpdb->get_var( $wpdb->prepare( $query ) );
//-- END CHECK FOR term_order column ---
//-- IF term_order column doesnt exist re-add it ---
$query = "
ALTER TABLE $wpdb->terms ADD term_order int(4) NOT NULL default 0;;
";
if($row_count==0)
{
$wpdb->query($query);
}
//-- END IF term_order column doesnt exist re-add it ---
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment