From 37d4ee490cd50392d61ccacfcb0caef1c79209a3 Mon Sep 17 00:00:00 2001 From: Zsombor Franczia Date: Mon, 24 Jun 2024 02:57:40 +0200 Subject: [PATCH] fix: ensure query loop block rendering respects user-defined limit --- includes/blocks/class-query-loop.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/includes/blocks/class-query-loop.php b/includes/blocks/class-query-loop.php index 43109b6c6..35f808013 100644 --- a/includes/blocks/class-query-loop.php +++ b/includes/blocks/class-query-loop.php @@ -51,10 +51,15 @@ public static function render_block( $attributes, $content, $block ) { ); $the_query = new WP_Query( $query_args ); + + $posts_count = 1; + $limit = isset ( $query_args['posts_per_page'] ) + ? $query_args['posts_per_page'] + : null; $content = ''; if ( $the_query->have_posts() ) { - while ( $the_query->have_posts() ) { + while ( $the_query->have_posts() && ( $limit === null || $posts_count <= $limit ) ) { $the_query->the_post(); $block_content = ( @@ -68,6 +73,7 @@ public static function render_block( $attributes, $content, $block ) { )->render( array( 'dynamic' => false ) ); $content .= $block_content; + $posts_count++; } }