} } $wpdb->insert('save_search_log', array('term' => trim(strtolower($search)))); self::updateIndex($search); } static function updateIndex($term, $single = false) { global $wpdb; $term = trim(strtolower($term)); $cur = $wpdb->get_var($wpdb->prepare("SELECT count FROM save_search_index WHERE single = %d AND term = %s", $single ? 1 : 0, $term)); if ($cur) { $wpdb->update('save_search_index', array('count' => $cur + 1, 'single' => $single), array('term' => $term)); } else { $wpdb->insert('save_search_index', array('term' => $term, 'single' => $single)); } } // retorna o número de vezes que o termo mais buscado foi buscado static function getTopCount() { global $wpdb; return $wpdb->get_var("SELECT count FROM save_search_index ORDER BY count DESC LIMIT 1"); } // retorna array com termos mais buscados, padrão 5 static function getTopTerms($count = 5) { global $wpdb; return $wpdb->get_col("SELECT term FROM save_search_index ORDER BY count DESC LIMIT {$count}"); } } SaveSearch::init();