Elasticpress: Plugin incompatibilty - Co-Authors Plus

Created on 28 May 2020  路  3Comments  路  Source: 10up/ElasticPress

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

  1. Install both Co-authors Plus and ElasticPress
  2. Activate ElasticPress in admin
  3. Visit Mine (wp-admin/edit.php?post_type=post&author=1)
  4. See empty results

* 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.

bug

All 3 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

blindpet picture blindpet  路  7Comments

jakejackson1 picture jakejackson1  路  8Comments

digiswede picture digiswede  路  6Comments

MediaMaquina picture MediaMaquina  路  5Comments

roditi3811 picture roditi3811  路  4Comments