From 0bc1cdc17b876629e77c8473750e9070b38c5e04 Mon Sep 17 00:00:00 2001 From: Tom Usborne Date: Mon, 18 Nov 2024 21:22:56 -0500 Subject: [PATCH 1/3] Fix: Query posts_per_page when set to -1 --- src/blocks/looper/components/LoopInnerBlocksRenderer.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/blocks/looper/components/LoopInnerBlocksRenderer.jsx b/src/blocks/looper/components/LoopInnerBlocksRenderer.jsx index 136c85eb0..f8a65d26d 100644 --- a/src/blocks/looper/components/LoopInnerBlocksRenderer.jsx +++ b/src/blocks/looper/components/LoopInnerBlocksRenderer.jsx @@ -223,7 +223,7 @@ export function LoopInnerBlocksRenderer( props ) { perPage = data.length; } - const items = data.slice( 0, perPage ); + const items = data.slice( 0, perPage > 0 ? perPage : data.length ); return items.map( ( item, index ) => { const { ID = null, id = null, type = 'post' } = item; From 2d02461afb69df17b45294c73e2f741677e15045 Mon Sep 17 00:00:00 2001 From: Tom Usborne Date: Mon, 18 Nov 2024 21:30:21 -0500 Subject: [PATCH 2/3] Fix existing perPage logic --- src/blocks/looper/components/LoopInnerBlocksRenderer.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/blocks/looper/components/LoopInnerBlocksRenderer.jsx b/src/blocks/looper/components/LoopInnerBlocksRenderer.jsx index f8a65d26d..677af6c64 100644 --- a/src/blocks/looper/components/LoopInnerBlocksRenderer.jsx +++ b/src/blocks/looper/components/LoopInnerBlocksRenderer.jsx @@ -219,11 +219,11 @@ export function LoopInnerBlocksRenderer( props ) { if ( hasResolvedData && Array.isArray( data ) ) { let perPage = query?.posts_per_page ?? 10; - if ( -1 === perPage ) { + if ( '-1' === perPage?.toString() ) { perPage = data.length; } - const items = data.slice( 0, perPage > 0 ? perPage : data.length ); + const items = data.slice( 0, perPage ); return items.map( ( item, index ) => { const { ID = null, id = null, type = 'post' } = item; From ffdd81fd7de4b7a47d1fc6c3c66f1a4500ac6fb5 Mon Sep 17 00:00:00 2001 From: Tom Usborne Date: Mon, 18 Nov 2024 21:34:41 -0500 Subject: [PATCH 3/3] Fix: No posts in the editor when `posts_per_page` is empty --- src/blocks/looper/components/LoopInnerBlocksRenderer.jsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/blocks/looper/components/LoopInnerBlocksRenderer.jsx b/src/blocks/looper/components/LoopInnerBlocksRenderer.jsx index 677af6c64..b9eb691a7 100644 --- a/src/blocks/looper/components/LoopInnerBlocksRenderer.jsx +++ b/src/blocks/looper/components/LoopInnerBlocksRenderer.jsx @@ -217,7 +217,9 @@ export function LoopInnerBlocksRenderer( props ) { const loopItemsContext = useMemo( () => { if ( hasResolvedData && Array.isArray( data ) ) { - let perPage = query?.posts_per_page ?? 10; + let perPage = query?.posts_per_page + ? query?.posts_per_page + : 10; if ( '-1' === perPage?.toString() ) { perPage = data.length;