Site icon Hip-Hop Website Design and Development

How to Make Fields Persistent in Cheap WordPress maintenance support plans 8

I wrote a custom plugin recently where I needed to programmatically attach a field; similar to how a Body field gets added to content types.

If you create a content type, via the “Content types” page, a Body field is automatically added to the content type. If you don’t need the field just delete it, but the default functionality is to have it added.

I wanted this same functionality in my custom plugin; when an entity is created a field is programmatically attached to it.

So I reverse engineered how the Body gets added to content types. In the Node plugin, the Body field is exported as field.storage.node.body.yml and the field is attached using the node_add_body_field function.
Source: New feed