Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

hasanrang05 on "add_filter with get_search_query executing 4 times"

$
0
0

I am trying to get search query string to submit custom table and count how many time these string searched

my table column
id(int), keyword(varchar), count(int)

everything i made my way but problem is when submit search form its count 4 times code following bellow.

function search_count($search) {

		//table column id, keyword, count
		// intial value 1, wordpress, 1
		global $wpdb;
		$table = "wp_search_count";
		$wpdb->query("UPDATE $table SET count = count+1 WHERE keyword = '$search'");

return $search;

}
add_filter( 'get_search_query', 'search_count');

i have started count value 1 and after submit search form its should be 2 but i get 5 for count value

Please kick me on the way ...
Thanks in Advance.


Viewing all articles
Browse latest Browse all 8245

Trending Articles