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; }