{"id":5744,"date":"2020-01-12T12:01:19","date_gmt":"2020-01-12T11:01:19","guid":{"rendered":"https:\/\/florianbrinkmann.com\/en\/?p=5744"},"modified":"2020-01-12T12:02:54","modified_gmt":"2020-01-12T11:02:54","slug":"metadata-post-update-block-editor","status":"publish","type":"post","link":"https:\/\/florianbrinkmann.com\/en\/metadata-post-update-block-editor-5744\/","title":{"rendered":"Get correct metadata after post update in block editor"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Sometimes it is necessary to do something after a post was saved. When using the old hooks like <code class=\"lang-php\">save_post<\/code> and <code class=\"lang-php\">post_updated<\/code>, the result is not as expected with the block editor: the metadata values are the old ones from before saving.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The <a href=\"https:\/\/developer.wordpress.org\/reference\/hooks\/rest_after_insert_this-post_type\/\" rel=\"noreferrer noopener\"><code class=\"lang-php\">rest_after_insert_{$this-&gt;post_type}<\/code> action hook<\/a> comes to the rescue (<code class=\"lang-php\">{$this-&gt;post_type}<\/code> needs to be replaced with the post type, for example, post or page). It gets the post object as the first param and when fetching data via <code class=\"lang-php\">get_post_meta()<\/code>, we get the correct data.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes it is necessary to do something after a post was saved. When using the old hooks like save_post and post_updated, the result is not as expected with the block editor: the metadata values are the old ones from before saving. The rest_after_insert_{$this-&gt;post_type} action hook comes to the rescue ({$this-&gt;post_type} needs to be replaced with [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"wpf_show_in_dewp_planet_feed":false,"flobn_post_versions":"","webmentions_disabled_pings":false,"webmentions_disabled":false,"lazy_load_responsive_images_disabled":false,"footnotes":""},"categories":[37],"tags":[],"class_list":["post-5744","post","type-post","status-publish","format-standard","hentry","category-wordpress"],"wp-worthy-pixel":{"ignored":false,"public":null,"server":null,"url":null},"wp-worthy-type":"normal","_links":{"self":[{"href":"https:\/\/florianbrinkmann.com\/en\/wp-json\/wp\/v2\/posts\/5744","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/florianbrinkmann.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/florianbrinkmann.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/florianbrinkmann.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/florianbrinkmann.com\/en\/wp-json\/wp\/v2\/comments?post=5744"}],"version-history":[{"count":4,"href":"https:\/\/florianbrinkmann.com\/en\/wp-json\/wp\/v2\/posts\/5744\/revisions"}],"predecessor-version":[{"id":5749,"href":"https:\/\/florianbrinkmann.com\/en\/wp-json\/wp\/v2\/posts\/5744\/revisions\/5749"}],"wp:attachment":[{"href":"https:\/\/florianbrinkmann.com\/en\/wp-json\/wp\/v2\/media?parent=5744"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/florianbrinkmann.com\/en\/wp-json\/wp\/v2\/categories?post=5744"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/florianbrinkmann.com\/en\/wp-json\/wp\/v2\/tags?post=5744"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}