From f662db446f3b99a2f38148ed496e90bcfb6ea68d Mon Sep 17 00:00:00 2001 From: deepench Date: Thu, 1 Oct 2026 12:09:13 +0545 Subject: [PATCH] Stop page widgets listing every page when none is selected With no pages chosen, the Image Services and Recent Work widgets passed an empty array as post__in. WP_Query treats that as no filter, so with posts_per_page set to -1 the widget printed every published page, including Cart, Checkout and My account. Image Services now renders nothing when no page is selected. Recent Work keeps its title and text and simply lists no pages. Widgets with at least one page selected are unchanged. Verified live: an unconfigured Image Services widget listed all five pages before and rendered nothing after; an unconfigured Recent Work with a title kept the title and text and went from five pages to none; with one page selected both still render that page. --- inc/widgets/accelerate-image-service-widget.php | 3 +++ inc/widgets/accelerate-recent-work-widget.php | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/inc/widgets/accelerate-image-service-widget.php b/inc/widgets/accelerate-image-service-widget.php index 1d721af..d7bdeb7 100644 --- a/inc/widgets/accelerate-image-service-widget.php +++ b/inc/widgets/accelerate-image-service-widget.php @@ -64,6 +64,9 @@ function widget( $args, $instance ) { if( !empty( $page_id ) ) array_push( $page_array, $page_id );// Push the page id in the array } + if( empty( $page_array ) ) { + return; + } $display_read_more = !empty( $instance[ 'display_read_more' ] ) ? 1 : 0; $get_featured_pages = new WP_Query( array( 'posts_per_page' => -1, diff --git a/inc/widgets/accelerate-recent-work-widget.php b/inc/widgets/accelerate-recent-work-widget.php index c7fd33f..5b74ea8 100644 --- a/inc/widgets/accelerate-recent-work-widget.php +++ b/inc/widgets/accelerate-recent-work-widget.php @@ -81,7 +81,7 @@ function widget( $args, $instance ) { $get_featured_pages = new WP_Query( array( 'posts_per_page' => -1, 'post_type' => array( 'page' ), - 'post__in' => $page_array, + 'post__in' => ! empty( $page_array ) ? $page_array : array( 0 ), 'orderby' => 'post__in' ) ); echo $before_widget;