After creating my Developers Handbook custom post type, I decided it would be fun to extend its functionality, and usefulness, by building a couple meta boxes. I thought this would be a great way to learn more about WordPress development.
In the end, I did learn a lot more about WordPress, but I ultimately gave up on the project and threw all my new code away.
Here’s the story.
I started this project by going back to the tutorial I used to create my custom post type.
It explained how to define the meta box, how to handle submitted data, and a little about how to display the meta box content. I also found How To Create Custom Post Meta Boxes In WordPress to be helpful.
In addition to creating the UI to extend the content management of my post type, I practiced working with nonces, verifying user permissions, sanitizing the submitted data before saving, and not saving during autosave.
All of that and I still didn’t really understand how to display the meta box content.
It didn’t take long to realize I should override the default single post type template in WordPress. It was in the tutorial I was using, but I didn’t get it at first.
I thought I would be able to include this file within my plugin. I mean, I assumed the appropriate solution was to include all plugin-related code within the plugin folder – a self-contained solution, so to speak.
I never figured out how to make that work and I’m still not sure I really know why – it seems like a reasonable solution. Anyway, all I could find about this said that my template file needed to be in the template folder. Well, okay, fine. I get that.
My Child Template
Now, I do know enough not to add my custom file to someone else’s template, and in this case – the twentysixteen template, so I created a child template.
I went simple: a style.css file, an archive file, and a single post file, and that was it for my child template.
I was finally starting to feel like I was getting somewhere… and then I realized I needed my meta box to have a repeatable field.
Advanced Custom Fields
After looking for a good way to create repeatable fields, I began to understand why I so often hear about the wonder of ACF.
I didn’t have to review ACF long to decide that it may not be necessary to program everything by hand to learn WordPress development.
I really did learn a lot.
Follow me on Twitter: @amelungc