diff --git a/src/Metadata/class-metadata-builder.php b/src/Metadata/class-metadata-builder.php index 99959862f..2a74af1ee 100644 --- a/src/Metadata/class-metadata-builder.php +++ b/src/Metadata/class-metadata-builder.php @@ -119,6 +119,21 @@ protected function build_type( WP_Post $post, string $parsely_type ): void { $this->metadata['@type'] = $type; } + /** + * Populates the custom metadata field with the current post's/page's ID. + * + * @since 3.16.0 + * + * @param WP_Post $post The post/page for which to populate the field. + */ + protected function build_post_id( WP_Post $post ): void { + $this->metadata['custom_metadata'] = wp_json_encode( + array( + 'wpParselyPostID' => $post->ID, + ) + ); + } + /** * Populates the mainEntityOfPage field in the metadata object. * diff --git a/src/Metadata/class-post-builder.php b/src/Metadata/class-post-builder.php index 8f1746684..a92ecf3ee 100644 --- a/src/Metadata/class-post-builder.php +++ b/src/Metadata/class-post-builder.php @@ -60,6 +60,7 @@ public function get_metadata(): array { $this->build_publisher(); $this->build_keywords( $this->post ); $this->build_metadata_post_times( $this->post ); + $this->build_post_id( $this->post ); return $this->metadata; } diff --git a/tests/Integration/Endpoints/RestMetadataTest.php b/tests/Integration/Endpoints/RestMetadataTest.php index 23854b34c..a449947a3 100644 --- a/tests/Integration/Endpoints/RestMetadataTest.php +++ b/tests/Integration/Endpoints/RestMetadataTest.php @@ -403,7 +403,8 @@ public function test_get_rendered_meta_json_ld(): void { $this->go_to( (string) $this->get_permalink( $post_id ) ); $meta_string = self::$rest->get_rendered_meta( 'json_ld' ); - $expected = ''; + $expected = '' . + ''; self::assertSame( $expected, $meta_string ); } @@ -471,7 +472,8 @@ public function test_get_rendered_repeated_metas(): void { -'; + +'; self::assertSame( $expected, $meta_string ); }