Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/wp-includes/post.php
Original file line number Diff line number Diff line change
Expand Up @@ -2523,6 +2523,12 @@ function delete_post_meta( $post_id, $meta_key, $meta_value = '' ) {
* An empty string if a valid but non-existing post ID is passed.
*/
function get_post_meta( $post_id, $key = '', $single = false ) {
// Make sure meta is get for the post, not for a revision.
$the_post = wp_is_post_revision( $post_id );
if ( $the_post ) {
$post_id = $the_post;
}

return get_metadata( 'post', $post_id, $key, $single );
}

Expand Down
19 changes: 19 additions & 0 deletions tests/phpunit/tests/post.php
Original file line number Diff line number Diff line change
Expand Up @@ -756,4 +756,23 @@ public function test_use_block_editor_for_post() {
$this->assertTrue( use_block_editor_for_post( $restless_post_id ) );
remove_filter( 'use_block_editor_for_post', '__return_true' );
}

/**
* Ensure get_post_meta does not try to get metadata from a revision
*
* @ticket 58763
* @covers ::get_post_meta
*/
public function test_get_post_meta() {
Copy link
Copy Markdown
Member

@adamsilverstein adamsilverstein Jun 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found this test passes before the patch. To test the fix it should fail before the patch is applied.

Also, the test probably belongs in tests/phpunit/tests/post/meta.php or tests/phpunit/tests/post/metaRevisions.php

$post_id = self::factory()->post->create();
$revision_id = self::factory()->post->create(
array(
'post_type' => 'revision',
'post_parent' => $post_id,
)
);

update_post_meta( $revision_id, 'test', 'testvalue' );
$this->assertSame( 'testvalue', get_post_meta( $revision_id, 'test', true ) );
}
}