Skip to content
Justin Tadlock edited this page Jul 10, 2015 · 14 revisions

Post Metadata standards for general use across multiple post types.

Current Standards

General naming standards for post metadata keys

All meta keys should meet the following standards.

  • Should be all lowercase.
  • Should be alphanumeric only.
  • Multiple words should be split with an underscore.

Additional naming guidelines

The following are additional guidelines for clarity.

  • There shall be no post type name attached.
  • Remove conjunctions (e.g., "with"), articles (e.g., "the") and other filler words from the meta key name.
  • The use of conditionals is allowed for boolean flags (e.g. has_*, is_*) as this is unavoidable to cover different context.

A note on using an underscore prefix for keys

Using a meta key like _my_meta_name hides the meta key from every user because it doesn't appear in the default Custom Fields meta box. Instead, you should use use the $auth_callback parameter when registering the metadata via the register_meta() function.

Otherwise, your users will have a terrible experience. The reason is simple: when you register a meta key with an underscore as the first character, you hide it from the user. This is OK as long as there is access to it when you have a custom meta box to alter the value. But, WordPress is broken if the user has no access to the data anymore.

A good rule of thumb of thumb to follow: Never use an underscore as first prefix for a meta key. Use the $auth_callback parameter for register_meta() instead.