I hope you can help me with a problem that I can not solve. I'm fixing the search on my wordpress site to show me all the posts in which an author appears, as main author or coauthor.
case 'autores':
$authors = implode( ',', eco_search_authors( $_GET['s'] ) );
$query->set ( 'author', $authors );
break;
The above code represents the filter I created to perform search by author.
/**
* Search for authors.
*
* @param string $search_author Expression to look for
* @return array Array of author IDs
*/
function eco_search_authors( $search_author ) {
$args = array (
'search' => '*'. esc_attr( $search_author ) . '*',
'fields' => 'ID',
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'first_name',
'value' => $search_author,
'compare' => 'LIKE'
),
array(
'key' => 'last_name',
'value' => $search_author,
'compare' => 'LIKE'
),
array(
'key' => 'description',
'value' => $search_author ,
'compare' => 'LIKE'
)
)
);
// Create the WP_User_Query object
$wp_user_query = new WP_User_Query($args);
// Get the results
$found_authors = $wp_user_query->get_results();
return $found_authors;
}
This part of the code is the function created to search the articles with the author that was searched.
What happens is that the search does not show all the articles of the searched author nor the articles in which the same author appears as coauthor.
Question: Has anyone ever come across this issue?