1

Upon theme activation I want to create an 'URL' key for the custom fields. Like in this screenshot.

I know who to run functions when a theme is activated, I don't know how to create this custom field key though. Any thoughts? I don't want to be using custom meta boxes.

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.