How to search for multiple listings by multiple values from single search bar
-
Hy there, I hope you are doing well
I’ve a search bar on inventory page of my website.
Right now the search bar is searching for vehicles based on their title. I want the same search bar to search for vehicles based on their ‘stock-number and ‘vin-number’ also.
like if someone searches for ‘Ford’ it should show the ford results but if someone searches the vehicle by its stock number like ‘d7923’ then it should also show listing with stock number of ‘d7923’ and same case for the vin number.
Right now I have this code which is checking the parameter in url and returning the value.
if(isset($_REQUEST['inventory_search']) && !empty($_REQUEST['inventory_search'])){ $inventory_search = $_REQUEST['inventory_search'][0]; $args['s'] = $inventory_search; $data = array( 'post_title' => $inventory_search, 's' => $inventory_search, 'compare' => 'LIKE', ); $datastock = array( 'key' => 'stock-number', 'value' => $inventory_search, 'compare' => 'IN' ); array_push($args, $data); array_push($args['meta_query'], $datastock); }
If i remove the first code
$args['s'] = $inventory_search;
then its working and showing the listings by their stock number but doing this will not work for search by title.
Any idea how i can implement this?
Remember it will be only 1 search bar.
Thanks
- The topic ‘How to search for multiple listings by multiple values from single search bar’ is closed to new replies.