Sign up ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have working search for a created wp_list_table. But i like to know how I can search in more than one column.

My current my working search setup in a Visitor class

//search something
$searchcol= array(
$search = !empty($_REQUEST["s"]) ?  mysql_real_escape_string($_REQUEST["s"]) : '';
//$search = preg_replace( "^$\**(.*)\**$?#", "*$1*", $_REQUEST["s"] );
if(!empty($_REQUEST["s"])) {$query .= ' WHERE '.$searchcol[1].' LIKE "%'.$search.'%"';}

here I just searching in the visitorName column, but i like to use the $searchcol to search in.

A foreach loop

foreach( $searchcol as $col) {
    if(!empty($_REQUEST["s"])) {$query .= ' WHERE '.$col.' LIKE "%'.$search.'%"';}

didn't work

share|improve this question

1 Answer 1

Ok i see my WHERE mistake

I made this working solution doesn't look pretty

$i =0;
        foreach( $searchcol as $col) {
            if($i==0) {
                $sqlterm = 'WHERE';
            } else {
                $sqlterm = 'OR';
            if(!empty($_REQUEST["s"])) {$query .=  ' '.$sqlterm.' '.$col.' LIKE "%'.$search.'%"';}
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.