In gutenberg I want to get a postmeta (it's a json string) that belongs to post #123. I want to check the editor's content against it. Let's say that postmeta's key is "blocks".

So I made this

(function () {
    if (true === window.location.pathname.includes('post.php')) {
        const unsubscribe = window.wp.data.subscribe(function () {
            const arr = JSON.parse('{"first":"1","second":"2"}');

            for (const key in arr) {

Which works, I can get the content, but I want to replace arr with the json that's in postmetas. Is there a way I can do this with wp.data? I can get current post's metas, but I want post #123's metas.

1 Answer 1


Here’s a way that could be “best” depending on the circumstance:

const { meta } = wp.data.select( 'core' ).getEntityRecord( 'postType', 'post', 123 );

This tutorial might be helpful for related stuff.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.