post_meta_cache

post_meta_cache is one more global variable used for caching as WordPress. It is a multi-dimensional array which stores the custom fields for a post. The custom fields are stored by the post ID and then by the custom field key. Multiple instances of custom fields are allowed.

Plugin and theme developers need not access post_meta_cache directly, it is used by WordPress internally in the following internal and template functions.

Internal Functions

  • add_post_meta($post_id, $key, $value, $unique = false): adds custom field with specified key and value to the specified post. If unique is true, another custom field with duplicate key is not added. This can be used by developers who are developing plugins for the the admin area, especially for adding more information to the post structure.
  • delete_post_meta($post_id, $key, $value): deletes the custom field with specified key and value from the specified post.
  • get_post_meta($post_id, $key, $single = false): returns custom field value for specified key for the specified post.
  • update_post_meta($post_id, $key, $value, $prev_value = ''): updates the custom field value for specified key in the specified post.

Template Functions

  • get_post_custom($post_id = 0): returns all the custom fields for specified post as an array. If post ID is not specified, current post is considered.
  • get_post_custom_keys(): returns keys of all the custom fields for specified post as an array
  • get_post_custom_values($key = ''): returns all values of the specified custom fields key for specified post as an array
  • post_custom($key = ''): returns all the custom fields with specified key for the current post.
  • the_meta(): displays all the custom fields of the current post as a unordered list.

Back to full list of global variables.

Technorati tags: , ,

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: