Store Post Meta with a Block Edit

Typically, blocks store their attribute values in the serialised block HTML. However, you can also create a block that saves its attribute values as post meta, which can be accessed programmatically anywhere in your template.

In this short tutorial you will create one of these blocks, which will prompt a user for a single value, and save it as post meta.

For background around the thinking of blocks as the interface, please see the key concepts section of the handbook.

Before starting this tutorial, you will need a plugin to hold your code. Please take a look at the first two steps of the JavaScript tutorial for information setting up a plugin.

Table of Contents

  1. Register Meta Field
  2. Add Meta Block
  3. Use Post Meta Data
  4. Finishing Touches