I need to get search results for posts on the basis of post-category(must) and posts-tags(optional).
The process is like:
- search for a string e.g. "bananas"
- the category is always static
- need to check banana term in post-title, descriptions and in post-tags
Currently I am using multiple tax_query but it shows results only in (tags) or in (post-title, descriptions). But I need the combined results.
Here is my code:
$catgory = 'case-definitions';
$terms = explode(' ', $_GET['s']);
$args = array(
's' => $_GET['s'],
'posts_per_page' => -1,
'post_type' => 'post',
'order' => 'DESC',
'tax_query' => array(
'relation' => 'OR',
array(
'relation' => 'AND',
array(
'taxonomy' => 'category',
'field' => 'slug',
'terms' => $catgory
),
array(
'taxonomy' => 'post_tag',
'field' => 'name',
'terms' => $terms
)
),
array(
'taxonomy' => 'category',
'field' => 'slug',
'terms' => $catgory
),
)
);
Can anyone please help me out to correct me? Much appreciated!