From 7b880889bc92552cdab7b0dd700db82a3885d02d Mon Sep 17 00:00:00 2001 From: hellofromTonya Date: Tue, 3 May 2022 14:33:12 +0000 Subject: [PATCH] Editor: Sets 'paged' query arg only when there are comments: `build_comment_query_vars_from_block()`. A SQL syntax error happened when a post has no comments and "Break comments into pages" is checked in Settings > Discussion. The fix sets the `'paged'` query arg only when there are comments. When there are no comments, `WP_Comment_Query` sets the default `'paged'` value to `1`. Props bernhard-reiter, luisherranz, czapla, cbravobernal, davidbaumwald, hellofromTonya. Follow-up to [53142], [53138]. Fixes #55658. Built from https://develop.svn.wordpress.org/trunk@53336 git-svn-id: http://core.svn.wordpress.org/trunk@52925 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/blocks.php | 5 ++++- wp-includes/version.php | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/wp-includes/blocks.php b/wp-includes/blocks.php index adaf1ae255..9df70abaf4 100644 --- a/wp-includes/blocks.php +++ b/wp-includes/blocks.php @@ -1325,7 +1325,10 @@ function build_comment_query_vars_from_block( $block ) { } elseif ( 'oldest' === $default_page ) { $comment_args['paged'] = 1; } elseif ( 'newest' === $default_page ) { - $comment_args['paged'] = (int) ( new WP_Comment_Query( $comment_args ) )->max_num_pages; + $max_num_pages = (int) ( new WP_Comment_Query( $comment_args ) )->max_num_pages; + if ( 0 !== $max_num_pages ) { + $comment_args['paged'] = $max_num_pages; + } } // Set the `cpage` query var to ensure the previous and next pagination links are correct // when inheriting the Discussion Settings. diff --git a/wp-includes/version.php b/wp-includes/version.php index 609e41e5cf..0fa55f675d 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.0-beta4-53335'; +$wp_version = '6.0-beta4-53336'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.