%%taxonomy%% %%term%%'){
global $wpdb, $scrib;
$suggestion = array();
$metaphone = $term_ids = array();
$term_ids = $term_ids + ($wpdb->get_col("SELECT term_id FROM $scrib->spelling_table WHERE term_name = '". ereg_replace('[^a-z|0-9| ]', '', strtolower(remove_accents($q))). "' ORDER BY term_count DESC LIMIT 5"));
$term_ids = $term_ids + ($wpdb->get_col("SELECT term_id FROM $scrib->spelling_table WHERE term_name LIKE '". ereg_replace('[^a-z|0-9| ]', '', strtolower(remove_accents($q))). "%' ORDER BY term_count DESC LIMIT 50"));
$term_ids = $term_ids + ($wpdb->get_col("SELECT term_id FROM $scrib->spelling_table WHERE term_name NOT LIKE '". ereg_replace('[^a-z|0-9| ]', '', strtolower(remove_accents($q))). "%' AND term_name LIKE '%". ereg_replace('[^a-z|0-9| ]', '', strtolower(remove_accents($q))). "%' ORDER BY term_count DESC LIMIT 50"));
foreach(explode(' ', remove_accents($q)) as $part)
$metaphone[] = metaphone($part);
if( implode( $metaphone , ' ' ))
$term_ids = $term_ids + ($wpdb->get_col("SELECT term_id FROM $scrib->spelling_table WHERE MATCH (term_metaphone) AGAINST ('". implode($metaphone, ' ') ."') LIMIT 15"));
if(!count($term_ids))
return(FALSE);
$in_taxonomies = "'" . implode("', '", $scrib->taxonomies_for_spelling) . "'";
foreach($term_ids as $term_id){
$term = $wpdb->get_row("SELECT t.name, tt.taxonomy FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy IN ($in_taxonomies) AND t.term_id = '$term_id' LIMIT 1");
$suggestion[] = str_replace(array('%%term%%','%%taxonomy%%','%%link%%'), array($term->name, $scrib->taxonomy_name[$term->taxonomy], $scrib->get_search_link(array($term->taxonomy => array($term->name)))), $template);
}
return($suggestion);
}
if($suggest = scrib_suggest($_REQUEST['s']))
echo ''. implode($suggest, "\n") .'
';
//print_r($wpdb->queries);
?>