Often when tutorials cover the how of doing a task they do not cover the why. And sometimes you need to understand what problem a feature solves so you can understand where to apply it.
If you have ever looked at the WordPress API or at the WordPress table structure you will find three tables which have the suffix ‘Meta’. What does that mean and what are they used for?
Well the Oxford English dictionary defines the word ‘Meta’ as :-
(Of a creative work) referring to itself or to the conventions of its genre; self-referential:
the enterprise is inherently ‘meta’, since it doesn’t review movies, for example, it reviews the reviewers who review movies
In my career as a codesmith I have always thought of meta in the terms of the word metadata. In other words data about data, and this is exactly what those three tables in WordPress are.
Let me expand on that idea a little.
If you imagine you are writing a simple system for a client and you are using WordPress as a base to write the system. Now WordPress comes with a lot out of the box but your client wants you to store some information about the users of your system, but WordPress, out of the box, does not have fields for them.
You could add an extra table to hold this information but that could lead to issues later on when upgrading WordPress or it could cause problems for your secondary audience if you have coded this system in a non-standard way.
Also it is more code to maintain and that will increase the probability of bugs because I can assure you that under most circumstances your code will not be as well tested as the core WordPress code.
Alternatively you could store data in the UserMeta table. No extra tables, no extra code when you don’t need it, and a standard WordPress approach which will be easier to maintain.
Maybe you are using WordPress as a knowledge base system for a client and you are using the Posts as the Q & A part. You again need to store extra data about the post than what WordPress provides, so it might be worth considering adding new tables. Personally in these circumstances I would use the PostMeta which exists for exactly this purpose.
The same argument applies to CommentMeta in my opinion.
You can access these tables using the appropriate API’s and you can add a visual element using the add_meta_box function, but I will save the detail of how to do this for later posts.
I hope this quick post has got you thinking about how to use meta data in WordPress and your plugin development. If you have more ideas on how you could use the meta tables in WordPress to make a plugin more maintainable then I would love to hear about it.