Create custom field key upon theme activation

Those values are populated from the unique keys in the *_postmeta table, excluding keys that begin with an underscore (_). If you want to pre-populate that key the add a value to the table under post ID 0. There is no way to pre-populate those that I am aware of besides to add a dummy meta_key/value to the *_postmeta table.

add_post_meta('0','URL',''); does not work, at least not when I try, so you need to write the SQL.

$wpdb->query("INSERT INTO {$wpdb->postmeta} (post_id,meta_key) values (0,'URL')");

That will create numerous entries in the database, however, unless you take further steps to avoid it.

I strongly advise against this hack.

Using a custom meta box is by far the cleaner solution, and I cannot guarantee that there are no negative consequences to adding a dummy key/value to *_postmeta. I highly recommend that you reconsider the custom meta box option.

Leave a Comment