How to prevent custom variables from auto populating when custom meta boxes are added?
Well.. this appeared to me as a trivial thing when a team mate googled for a solution to this few months back. But recently we faced this situation again and when I was asked for a solution I was like.. ahhmm ahmmm….
So thought of “pressing” it for future references and for everyone our there!
While creating custom variables appears the most convenient way of keeping a track of post specific additional information, this at times does not proves a very good solution where you have hosts of such “additional information” to store, as each time one posts he/she has to remember the KEY of custom variables. In such situations comes in picture the mighty META BOX. One can easily add a meta box to let user add “additional information”, this internally gets saved like a custom variable [post meta to be precise] but then this time you are not the one remembering the key of this custom variable, but WP is doing it for you.
But this again creates one problem [may not look like a problem for all, but for some!]. Due to this, every time you enter information, WP will display this custom variable in the ADD/EDIT custom variable box/section .
To avoid this, simply add “_” [underscore] at the beginning of your custom variable’s key and that’s it.
Say for example: You have a custom variable called: publish_location.
So you have to change it to : _publish_location
Hope it helps someone!