We’re back with part 2 of Using Custom Post Meta in the Thesis theme and we’re talking about the typical WordPress way for creating post meta which can be quite complicated. There’s a good example of it being described here at smashingmagazine.com. It has a nice article here describing how to do it and it’s fairly clear, fairly well-defined and described but there’s an awful lot of steps that you have to go through in order to accurately make this work.
Essentially what you’re doing is manually coding everything here to create this custom post meta. The first thing you have to do is setup the meta box, create the form for collecting that meta data, secure the form to prevent unauthorized updates, you have to collect the form data and make sure the data is from a trusted source then you have to compare the new data to the existing data and finally, you update the existing data with the new data.
That is lots of steps where you have code that doesn’t necessarily makes sense. Not that the code itself doesn’t make sense it’s just code that you haven’t seen before. For example, setting up wp_nonce_field or numbers used once fields and things like that. There’s just a bunch of, if you will, highly technical code involved in creating one of these meta boxes.
This used to be the way lots of things were done in WordPress. For example, prior to 2.8, you had to do plugins settings and theme settings this way. In 2.8, WordPress came out with the settings API and it took this very complicated system of creating theme or plugin settings and created a nice simple API for it which resulted in only really need to do 3 things.
You needed to define the settings fields, create the form and sanitize the data but you didn’t need to worry about all the security associated with saving it, updating it and checking the new version against the old version. That all happened automatically inside the API so the steps for creating settings fields became quite a bit simpler once the settings API came into place.
Genesis Meta Box API
There is no meta box API in WordPress yet so WordPress obligates you then to go through this fairly complex set of processes to create a meta box and this has been complicated enough that it has spun a number of solutions. For example if you’re a Genesis user, the Genesis theme, at least with 1.8 came out with the Genesis Meta Box API which significantly simplifies the process of creating meta boxes in Genesis and is a nice system if you’re using Genesis.
Now, in the Thesis theme, Chris Pearson, has been hinting that 2.0 is going to have this killer meta box creation so when 2.0 comes out, this lesson may be obsolete and we may have to redo it for 2.0 but for the time being, the Thesis theme doesn’t have anything.
Verve Meta Boxes Plugin
I’ve never taught this material in a class before and what I’ve done instead of teaching this material as I’ve taught how to use a plugin so I use the plugin Verve Meta Boxes because it lets you create these meta boxes and store the data then all we had to do is create a program to retrieve that data. But the purpose for this class is to teach you how to actually program it yourself but there are a number of plugin solutions out there.
WPAlchemy Metabox Class
There is a class called the WPAlchemy Metabox Class that is created which is essentially an API for streamlining the process of creating post meta in WordPress. It’s this API that I’m going to be teaching you how to use because the API does what the WordPress settings API does which is, handles all of the backend things behind the scenes and gives you a fairly simple way of creating new meta boxes.