Make WordPress Core


Ignore:
Timestamp:
05/03/2022 02:31:12 PM (2 years ago)
Author:
hellofromTonya
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/blocks.php

    r53332 r53336  
    13261326                $comment_args['paged'] = 1;
    13271327            } elseif ( 'newest' === $default_page ) {
    1328                 $comment_args['paged'] = (int) ( new WP_Comment_Query( $comment_args ) )->max_num_pages;
     1328                $max_num_pages = (int) ( new WP_Comment_Query( $comment_args ) )->max_num_pages;
     1329                if ( 0 !== $max_num_pages ) {
     1330                    $comment_args['paged'] = $max_num_pages;
     1331                }
    13291332            }
    13301333            // Set the `cpage` query var to ensure the previous and next pagination links are correct
Note: See TracChangeset for help on using the changeset viewer.