Co-Authors-Plus icon indicating copy to clipboard operation
Co-Authors-Plus copied to clipboard

Support Elasticsearch powered WP Queries

Open WPprodigy opened this issue 6 years ago • 1 comments

If you are offloading queries to ES, then there is a particular problem when filtering posts by author and using CAP (co-authors plus). This can be seen both in the admin and on the author archives in the frontend (the co-authored post only appears for the first author).

This happens because ES can only use the WP Query args to formulate it's own query, and CAP manipulates the SQL directly: https://github.com/Automattic/Co-Authors-Plus/blob/master/co-authors-plus.php#L81-L85.

I first tried to get CAP to just use pre_get_posts and only manipulate query args there, but the underlining need is that it has to look for posts that are attached as the main post author OR attached via the 'author' taxonomy. And there is no built-in way to do this in WP Query, as it ends up being post_author AND taxonomy match, not OR.

So enough backstory :), you can see some replication steps and more info about this in #84768-zd.

This is the solution we ended up with: https://gist.github.com/WPprodigy/a6e42dcb94bf4fb93201cf9065d79a7f. It may need some additional fine tuning, but is a good starting place.

WPprodigy avatar Nov 15 '18 21:11 WPprodigy

Another example in #108663-zd for more study when addressing this.

WPprodigy avatar Jun 03 '20 19:06 WPprodigy