From c6a1534f3d0f9eea2dc8735a58b388067b55444d Mon Sep 17 00:00:00 2001 From: Juzar Bharmal <53657281+Juzar10@users.noreply.github.com> Date: Tue, 10 Dec 2024 17:18:00 +0530 Subject: [PATCH] fix: the empty object being passed for the wp_query object --- src/wp-includes/class-wp-query.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/wp-includes/class-wp-query.php b/src/wp-includes/class-wp-query.php index f95cb6149fc43..cf90f35dbb7b5 100644 --- a/src/wp-includes/class-wp-query.php +++ b/src/wp-includes/class-wp-query.php @@ -3662,14 +3662,24 @@ private function set_found_posts( $q, $limits ) { * * @since 1.5.0 * - * @return WP_Post Next post. + * @return WP_Post|int Next post. */ public function next_post() { ++$this->current_post; - /** @var WP_Post */ - $this->post = $this->posts[ $this->current_post ]; + if ( $this->posts[ $this->current_post ] instanceof WP_Post ) { + $this->post = $this->posts[ $this->current_post ]; + } else { + $current_item = $this->posts[ $this->current_post ]; + + if ( is_object( $current_item ) && property_exists( $current_item, 'ID' ) ) { + $this->post = $current_item->ID; + } else { + $this->post = $current_item; + } + } + return $this->post; }