Co-Authors-Plus
Co-Authors-Plus copied to clipboard
Incorrect post count when linked accounts are authors of the same post prior to linking
Steps to reproduce
- Create an editor account (editor-779)
- Create one post (test-post-779)
- Create a guest author account (guest-779)
- Add guest author to post (test-post-779)
- Check post count for editor and guest author
- Link guest author account (guest-779) with editor account (editor-779)
- Check post count for editor and guest author
Expected behaviour
✅ Editor: 1 post ✅ Guest: 1 post
Current behaviour
❌ Editor: 2 posts ❌ Guest: 2 posts
Related issue
https://github.com/Automattic/Co-Authors-Plus/pull/776
For this issue, what I would suggest is looking at how you can alter the query here: https://github.com/Automattic/Co-Authors-Plus/blob/master/co-authors-plus.php#L591
The query that's output:
SELECT COUNT(wp_posts.ID)
FROM wp_posts
LEFT JOIN wp_term_relationships
ON (wp_posts.ID = wp_term_relationships.object_id)
LEFT JOIN wp_term_taxonomy
ON ( wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id )
WHERE (wp_term_taxonomy.term_id = 5)
AND wp_posts.post_type IN ('post')
AND wp_posts.post_status = 'publish'
GROUP BY wp_posts.ID
HAVING MAX( IF ( wp_term_taxonomy.taxonomy = 'author', IF ( wp_term_taxonomy.term_id = 5,2,1 ),0 ) ) <> 1
`
This runs on `save_post` right now but I'm wondering if we could use this existing query and alter it to show a correct count after there's been a guest author linked to a regular user.
Thanks for pointing out that section, @mikeyarce.