Let’s recap what a meta box is and why and when you should build a custom one. A meta box is a UI (user interface) component to allow interactivity with content but without the technical aspects. Think about that statement. A meta box makes it easy to interact with content by adding, editing, deleting, etc.
WordPress comes with a built Custom Field meta box. That interface is fine for simple projects or your own stuff.
But for clients, we want to make it easier, more intuitive, and less technical. A meta box lets us abstract away the complexity such as remembering the correct meta key name or value type.
Repeat after me: A meta box is not magical.
It’s not. It’s merely:
- An add function to register the meta box with WordPress.
- A render function to send the HTML out to the browser.
- A save function to take what the person changed and send it to the database for storage.
- A view file for the HTML.
That’s it. I’ll show you in this lab.
Break. Go rest your noodle for a couple of minutes.
Total Lab Runtime: 02:21:18
- 1 Lab Introductionfree 07:20
- 2 What is a Meta Box?free 07:28
- 3 Add a New Meta Boxpro 11:46
- 4 Meta Box HTMLpro 18:39
- 5 Save Process & $_POSTfree 12:33
- 6 Bail Out if Not Our Meta Boxpro 05:03
- 7 Nonce Security Checkpro 10:16
- 8 On Save - Update or Delete Custom Field?pro 12:03
- 9 Validate & Sanitize BEFORE Updating Databasefree 14:41
- 10 Add Another Custom Fieldpro 08:49
- 11 Making Save Easier with $_POST Keypro 05:32
- 12 Better Saving Strategy for Multiple Custom Fieldspro 14:47
- 13 Changing Where Meta Box Appearspro 06:02
- 14 Passing Arguments to Renderpro 02:18
- 15 Wrap & Making it Reusablepro 04:01