I'm trying to write an query that should find a post by search-term or tag-name. But when i add the tag name the search stops working.
$mainQuery = new WP_Query(array(
'post_type' => array('coworker', 'post', 'page', 'news'),
's' => sanitize_text_field($data['term']),
'relation' => 'OR',
'tag' => array(
'tag' => sanitize_text_field($data['term'])
)
));
What have i done wrong here?
There are two issues with your code:
tax_query
and meta_query
arguments.Depending on your implementation, you likely need to run two queries and merge the results, as you want either OR result.