How to specify multiple search columns for wp list table search

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

Read More
//search something
$searchcol= array(
    'visitorCompany',
    'visitorName',
    'visitorEmail'
    );  
$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

Related posts

Leave a Reply

1 comment

  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.'%"';}
                $i++;
            }