Describe the bug
Co-Authors Plus plugin enables to create Guest authors - authors that don't have a login. For that it creates a taxonomy 'author' which is used for displaying post author information. This causes a problem with Search query since ElasticPress\Indexable\Post::format_args creates a query that returns 0 results. That especially obvious in WP administration when viewing "Mine" posts, or any other that are accessed with author param (wp-admin/edit.php?post_type=post&author=1).
Steps to Reproduce
* Quick fix solution *
We should find a way to avoid this. I have personally avoided this by editing ElasticPress\Indexable\Post. I have added a quick fix after line 767:
if ( 'author' === $tax_slug ) {
continue;
}
I am filling in this report to help others while I search for a more complete solution. Any direction with this will be helpful.
This issue has more edge cases. Search with author_name should be directed to terms. Below is the fix for that and the "Mine" posts. I will update this thread as new issues and solutions come up.
add_filter( 'ep_formatted_args', 'fix_coauthors', 10, 2 );
function fix_coauthors($formatted_args, $args) {
if (!empty($formatted_args['post_filter']['bool']['must'][0]['term']['post_author.display_name'])) {
$formatted_args['post_filter']['bool']['must'][]= [
'bool' => [
'must' => [
['terms' => ['terms.author.slug' => [$formatted_args['post_filter']['bool']['must'][0]['term']['post_author.display_name']] ]]
]
]
];
unset($formatted_args['post_filter']['bool']['must'][0]);
}
if (!empty($formatted_args['post_filter']['bool']['must'][0]['bool']['must'][0]['terms']['terms.author.slug'][0]) && ($formatted_args['post_filter']['bool']['must'][0]['bool']['must'][0]['terms']['terms.author.slug'][0] == 1)) {
unset($formatted_args['post_filter']['bool']['must'][0]);
}
return $formatted_args;
}
@mbanusic could you try out the branch from #1851 and provide feedback there if that's helping cover your use case with Co-Authors Plus?
Per feedback in #1851 this fix seems to work and we are adding it to Elasticpress Labs.