Skip to content

Conversation

@PatelUtkarsh
Copy link
Contributor

What does this implement/fix? Explain your changes.

When meta is stored as serialize array in post meta table, during preview instead of returning array it returns first value from array.

When $single is true, WordPress core's get_post_metadata filter returns the first value from an array. This fix ensures proper array wrapping to return array back when stored value is array.

Ref: https://github.com/WordPress/wordpress-develop/blob/2fe26ceb7a1f3fb57ec8726fc5f425d00a12ace9/src/wp-includes/meta.php#L666

Does this close any currently open issues?

Any other comments?

…ew meta

When $single is true, WordPress core's get_post_metadata filter returns
the first value from an array. This fix ensures proper array wrapping
to maintain expected behavior in GraphQL preview requests.

Ref: https://github.com/WordPress/wordpress-develop/blob/2fe26ceb7a1f3fb57ec8726fc5f425d00a12ace9/src/wp-includes/meta.php#L666
@jasonbahl
Copy link
Collaborator

@PatelUtkarsh thanks for this PR!

Would you have any interest in contributing a test for this? An ideal test would be one that makes a preview query that includes meta and fails without this fix in place but passes with this fix in place.

@coveralls
Copy link

coveralls commented Oct 1, 2025

Coverage Status

coverage: 84.575% (+0.001%) from 84.574%
when pulling 8b120d6 on PatelUtkarsh:fix/preview-meta-array
into b3ce4f0 on wp-graphql:develop.

@PatelUtkarsh
Copy link
Contributor Author

@jasonbahl I've added tests in latest commit.

@jasonbahl
Copy link
Collaborator

Thanks @PatelUtkarsh! 🙌🏻

@jasonbahl jasonbahl merged commit 0ffe5b0 into wp-graphql:develop Oct 2, 2025
36 of 37 checks passed
pull bot pushed a commit to Zezo-Ai/wp-graphql that referenced this pull request Oct 3, 2025
@PatelUtkarsh
Copy link
Contributor Author

Hello @jasonbahl, I couldn't figure out how to run the specific file / method in the setup, I tried setting up SUITS env. Do you have any advice on that?

SUITES="wpunit tests/wpunit/PreviewTest.php:testPreviewMetaWithArrayValueAndSingleTrue" composer run-test

@jasonbahl
Copy link
Collaborator

@PatelUtkarsh

super close! Instead of wpunit $pathToTest just do $pathToTest

SUITES="tests/wpunit/PreviewTest.php:testPreviewMetaWithArrayValueAndSingleTrue" composer run-test

@PatelUtkarsh PatelUtkarsh deleted the fix/preview-meta-array branch October 3, 2025 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants