From 442a07377ac7623b94a29bc79e18b170b08ead8f Mon Sep 17 00:00:00 2001 From: Tom J Nowell Date: Tue, 21 Feb 2023 15:09:14 +0000 Subject: [PATCH] Fix #3325 Set the current post when indexing posts When indexing a post, the content gets rendered, and shortcodes/blocks/etc may rely on the global `$post` variable to provide context that will be missing when performing an ES index. In my case it was a block which did not handle the value being missing, but context dependent content would generate PHP warnings/errors or incorrect data --- includes/classes/Indexable/Post/Post.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/includes/classes/Indexable/Post/Post.php b/includes/classes/Indexable/Post/Post.php index 3b68ba6f11..fc944a0ff3 100644 --- a/includes/classes/Indexable/Post/Post.php +++ b/includes/classes/Indexable/Post/Post.php @@ -420,7 +420,9 @@ public function determine_mapping_version() { * @return bool|array */ public function prepare_document( $post_id ) { + global $post; $post = get_post( $post_id ); + setup_postdata( $post ); if ( empty( $post ) ) { return false;