Problem with counting the pending posts
-
On WordPress 6.9, the pending posts count in the admin is inflated because fltPostCountQuery() in
admin-posts_rvy.php no longer recognizes the wp_count_posts() SQL query. Revision posts (with post_mime_type like
pending-revision) are incorrectly counted as regular pending posts.Steps to reproduce
- Install WordPress 6.9 with PublishPress Revisions Pro 3.7.22
- Have posts with pending revisions (e.g. 19 pending-revision posts + 3 real pending posts)
- Navigate to Posts → All Posts → Pending (edit.php?post_status=pending&post_type=post)
- Observe: the count badge shows 22 but only 3 posts are listed
Root cause : WordPress 6.9 changed the SQL formatting of
wp_count_posts():#WP 6.8:
SELECT post_status, COUNT( * ) AS num_posts FROM wp_posts WHERE post_type = 'post' GROUP BY post_status
#WP 6.9:
SELECT post_status, COUNT(*) AS num_posts
FROM wp_posts
WHERE post_type = 'post'
GROUP BY post_statusTwo breaking changes:
- COUNT( * ) → COUNT(*) (spaces removed)
- Single-line query → multiline with indentation The strpos check on https://github.com/publishpress/PublishPress-Revisions/blob/master/admin/admin-posts_rvy.php
looks for the exact string “ELECT post_status, COUNT( * ) AS num_posts ” which no longer matches. Suggested fix
Suggested fix: Replace the strpos with a preg_match that tolerates both formats:
// Before:
if ((strpos($query, "ELECT post_status, COUNT( * ) AS num_posts ") || (strpos($query, "ELECT COUNT( 1 )") &&
$pos_from && (!$pos_where || ($pos_from < $pos_where))))
&& preg_match("/FROM\s*{$posts}\s*WHERE post_type\s*=\s*'([^ ]+)'/", $query, $matches)
) {
// After:
if ((preg_match("/ELECT post_status, COUNT\(\s*\*\s*\) AS num_posts/", $query) || (strpos($query, "ELECT COUNT( 1
)") && $pos_from && (!$pos_where || ($pos_from < $pos_where))))
&& preg_match("/FROM\s+{$posts}\s+WHERE post_type\s*=\s*'([^ ]+)'/", $query, $matches)
) {Environment
- WordPress 6.9
- PublishPress Revisions Pro 3.7.22
- PHP 8.2
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
You must be logged in to reply to this topic.