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

Incorrect post count when linked accounts are authors of the same post prior to linking

Open nielslange opened this issue 4 years ago • 2 comments

Steps to reproduce

  1. Create an editor account (editor-779)
  2. Create one post (test-post-779)
  3. Create a guest author account (guest-779)
  4. Add guest author to post (test-post-779)
  5. Check post count for editor and guest author
  6. Link guest author account (guest-779) with editor account (editor-779)
  7. 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

nielslange avatar Apr 15 '21 04:04 nielslange

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.

mikeyarce avatar Apr 16 '21 21:04 mikeyarce

Thanks for pointing out that section, @mikeyarce.

nielslange avatar Apr 19 '21 01:04 nielslange