I'm new to PHP and I don't know how write a wp_query for search by category. basically i have a website in which i have posts now i want to search accurate post by its name model and year i also attached the screenshot.
i was searching for code but i didn't find anything only find this code but i didn't know what to do in this.
check this website their is a reference searchbar
https://www.thecarconnection.com/
code:
<?php
$text=$_GET['car'];
$model=$_GET['model'];
$year=$_GET['year'];
if($text!="" && $model=="" && $year=="" )
{
$the_query = new WP_Query( array(
'post_type' => 'Posts',
'paged' => $paged,
'meta_query'=>array(
array(
'key'=>'prp_ulocation',
'value'=>$text,
'compare'=>'LIKE'
)
)));
}
else if($text=="" && $model!="" && $year!="" )
{
$the_query = new WP_Query( array(
'post_type' => 'BMW',
'paged' => $paged,
'meta_query'=>array(
array(
'key'=>'model',
'type'=>'NUMERIC',
'value'=>array($model,$year),
'compare'=>'BETWEEN'
)
)));
}
else if($text=="" && $model=="" && $year=="" )
{
$the_query = new WP_Query( array(
'post_type' => 'Kia',
'paged' => $paged,
'meta_query'=>array(
array(
'key'=>'model',
'type'=>'NUMERIC',
'value'=>$model,
'compare'=>'<='
)
)));
}
else if($text!="" && $model=="" && $year=="" )
{
$the_query = new WP_Query( array(
'post_type' => 'Toyota',
'paged' => $paged,
'meta_query'=>array(
array(
'key'=>'model',
'type'=>'NUMERIC',
'value'=>$model,
'compare'=>'<='
),
array(
'key'=>'year',
'value'=>$text,
'compare'=>'LIKE'
)
)));
}
while ( $the_query->have_posts() ) : $the_query->the_post();
?>
their will be a form