I am using this php code for MySQL database query:
function search_it() {
if ( isset( $_GET['s'] ) ) {
global $wpdb;
$address_table = $wpdb->prefix . 'my_products';
$search = $_GET['s'];
$search = trim($search);
$keywords = explode(" ", $search);
foreach($keywords as $search) {
$search = "%{$search}%";
$where = $wpdb->prepare( 'WHERE name LIKE %s OR price LIKE %d OR id LIKE %d OR market_price LIKE %d OR image_url LIKE %s LIMIT 0,30' , $search, $search, $search, $search, $search );
}
$results = $wpdb->get_results( "SELECT * FROM {$address_table} {$where}" );
return $results;
}}
for example my database have these lines
This is a blue car
This is a white car
This is a red car
This car color is blue
This is a yellow car
This is a blue bike
This car name is bluebird
Blue car looks awesome
When i execute the above code, with query blue car
then it will show me all results which contain CAR and all results which contain BLUE
But i want it show me the only results which contain keyword BLUE and CAR even these keywords are saved in any order in database
I want it show me only these results, when i search for blue car
This is a blue car
This car color is blue
This car name is bluebird
Blue car looks awesome
Above keywords are just for example it would any