Bug in Category Count – wpmediacategory_update_count_callback
-
Hi,
It seems that your plugin, specifically function wpmediacategory_update_count_callback is overriding the correct default Count of posts.
Your query is including post revisions. For example I have got 3 posts in Category A, which I edited a few times.
When I add an image (through your plugin) to a category B, you are looping through all categories and updating total which is found in term_relationships but you don’t check that some of those are actually not published posts but revisions.
I didn’t go deeper just updated your query to get the numbers right, but I don’t count actual images in categories as they are now excluded due to my selection p.post_status=’publish’.
You would need to:
a) ideally, don’t override all categories, only the one which was updated with a new image or image removed and make sure to exclude revisions or
b) if you loop and update all categories make sure you are not counting revisions for postsSELECT term_taxonomy_id, MAX(total) AS total FROM (( SELECT tt.term_taxonomy_id, COUNT(*) AS total FROM wp_term_relationships tr, wp_term_taxonomy tt <strong>, wp_posts p</strong> WHERE tr.term_taxonomy_id = tt.term_taxonomy_id <strong>AND tr.object_id = p.ID</strong> AND tt.taxonomy = 'category' <strong>AND p.post_status='publish'</strong> GROUP BY tt.term_taxonomy_id ) UNION ALL ( SELECT term_taxonomy_id, 0 AS total FROM wp_term_taxonomy WHERE taxonomy = 'category' )) AS unioncount GROUP BY term_taxonomy_id
The only way at the moment to get the correct Count back in categories, is to disable your plugin, and update one random post in each category to get the numbers correct.
- The topic ‘Bug in Category Count – wpmediacategory_update_count_callback’ is closed to new replies.