Post meta: block editor vs. PHP #53150
Replies: 3 comments
-
Also, if I replace If I use Should |
Beta Was this translation helpful? Give feedback.
-
Most definitely have to test some more, but I think what I may have been after all this time was
|
Beta Was this translation helpful? Give feedback.
-
Possibly related to the second (less important, because I can poll for background updates, although this where I was struggling with initially) question: #47746 |
Beta Was this translation helpful? Give feedback.
-
Not sure this is the correct place to ask, but if someone can point me to some resource elsewhere, that'd be great too.
So, I need to expose post meta to the block editor.
I'd read about
const [ meta, setMeta ] = wp.coreData.useEntityProp( 'postType', postType, 'meta' )
and so on, so I started using that (for display purposes, at first). And all was well, intially.Except, changes (to post meta) made on the server -- lets just say I use
wp_schedule_single_event()
immediately after publishing, to do some API stuff -- are not automagically picked up, i.e.,meta
does not reflect the latest and greatest status. Don't think it can, to be honest.Okay, I thought, I'll grab this (updated) metadata from a custom REST endpoint then, no worries.
Except, of course, that if I then update the post or some of its metadata, that the old values overwrite the later ones.
So I tried "unsetting" some of the above
meta
object's properties, or pass (tosetMeta()
) a copy ofmeta
with those properties left out. Doesn't seem to be working. Plus, other plugins could obviously still "save" the "original" meta object.I also tried updating
meta
with the new values from the server. But what if the (database) value again changes? (Has "Asking for trouble" written all over it.) Plus, some other plugin could obviously still "save" the "original" meta object.So, how do you deal with this?
Is there a way to
register_post_meta()
but keep it "read-only"? Using anauth_callback
trick? Some JS magic? Or is a custom API endpoint the only way? And should I useregister_post_meta()
only for anything that is allowed to be edited in the editor? The docs, I'm afraid, could be a little clearer ...And, is there a way to "better" sync in-editor post meta with whats going on server-side? (The classic editor does not suffer from this nearly as much, as the entire page (including all meta boxes, where you'd typically deal with this stuff) gets reloaded with every change/save.)
Beta Was this translation helpful? Give feedback.
All reactions