WP Query – Search in title or author_name

My need is to have a WPQuery that searches for posts which title is ‘test’ OR author_name is ‘test’.

Here is the code I tried:

$search_query = get_search_query();

$args = array(
‘relation’ => ‘OR’,
array(
‘key’ => ‘title’,
‘value’ => $search_query,
‘compare’ => ‘LIKE’
),
array(
‘key’ => ‘author_name’,
‘value’ => $search_query,
‘compare’ => ‘LIKE’
)
);
$wp_query = new WP_Query($args);

I know that this code is meta_query style, but I’m trying to have OR in WP_Query

Read more here:: WP Query – Search in title or author_name

Leave a Reply

Your email address will not be published. Required fields are marked *