WP Query – Search in title or author_name

Question

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

0
, , Mattia Merlini 8 months 0 Answers 94 views 0

Leave an answer