I want to write a query for my search page to show posts by two inputs. In my search form, i have to inputs, one is for category and the other is regular search term.
I want to show the posts that have the category keyword and search term. This is the code i have wrote so far :
$_place = $_GET['s'] != '' ? $_GET['s'] : ''; $_name = $_GET['n'] != '' ? $_GET['n'] : ''; $meta_query_args = array( 'key' => 'keywords', 'value' => $_name, 'compare' => 'LIKE' ); $tax_query = array( 'taxonomy' => 'category', 'field' => 'slug', 'terms' => $_place, 'operator' => 'LIKE' ); $adSearchQuery = new WP_Query( array( 'post_type' => 'post', 's' => $_name, 'meta_query' => $meta_query_args, 'tax_query' => $tax_query ) );
$_place is the category. This code does not show any related result, in fact, most of the times it does not show anything.
So my main question is i want to show posts by similar terms (
$_name) and similar categories (
By similar, i mean when i search the
abc keyword, it shows the
h abc d .