Think about an array. The data being posted back when you click publish or update is stored in an array within the superglobal
$_POST (i.e. within the web server and PHP). It’s an array of content.
Okay, now think about grouping and namespacing. Does it make sense in your mind that we have one key for our meta box and therefore, one entry in the
$_POST? Think about that. That meta box key then would have an array with all of our custom fields’ values.
Walking down that thought process, how could we implement this strategy?
What are the advantages to this strategy?
- Our meta box check is easier and it relates to the meta box directly with just one key to check in
- Grouping of our metadata.
- Merging defaults is much easier.
- Removing the redundant code, as we can loop through the metadata for the delete and update code.
Don’t repeat yourself. Don’t repeat yourself. Don’t repeat yourself.
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