FREELessons: 6Length: 32 minutes

Next lesson playing in 5 seconds

Cancel
  • Overview
  • Transcript

3.1 Conclusion

Let's recap what's been covered in the course and what you've learned.

3.1 Conclusion

Hello, and welcome back to this TutsPlus course on creating custom meta boxes in WordPress. In this course, I demonstrated how to create two meta boxes appearing in different places on the post editing screen. And the first one was a meta box for post metadata or custom fields. Which appears directly below the post content. So we added this meta box for a user to add today's weather and save that as post metadata. The second meta box that we added was a text box over here on the right, designed to provide instructions to help somebody using the post editing screen. So to do this, we created two plugins. This first plugin is for our Meta Box underneath the post content. And this one included a callback function to populate the Meta Box as well as a save function to save data to the database as that post metadata. So we created our tutsplus_post_metabox function. Which we hoped to the add meta boxes action. We then created a callback function and then within that callback, we added a nonce field. We extracted the current value of the tutsplus weather field and save that to the weather variable. And then we created a label and an input field for a user to input a new value to that custom field. Having done that, we had to set things up so that WordPress would actually save any data added to that field. So we created a second function called save post meta box, which checks for the nonce and also whether the current user has the correct capability to edit this post. And if so, it sets the new value of this custom field tutsplus weather to the value that's been entered into our field, our input element up here. And then we hook that to the save post action. So if we run every time a post is saved. The second plugin we created was similar but designed to create a text meta box. So we didn't need to include a save function. So this use the add meta box function once again, with similar parameters, except we put it on the side instead of the normal section of the post editing screen. And then we added another callback function, which populated our box with html. Once we've done that, we went on to examine how these meta boxes would be affected by the Guttenberg editor. So the first meta box is in the same place underneath the post content. The second meta box because we added it over here in the side, has been added by Guttenberg to this extended settings area. At the moment under Gutenberg, we don't have any extra functionality we can use to give more control over that. Now you follow the course, you'll have a better understanding of how to create custom meta boxes in WordPress and use them to save data. I hope you found this course useful. Thanks for watching.

Back to the top