add_post_meta() – Function description, parameters and basic usage

Description:

add_post_meta is a WordPress function which Adds a custom field value to a post by given ID. Very useful for storing additional data to post(like dates for sorting, thumbnail image, links etc..). I`m actively using it with custom post types.

Parameters:

$post_id (required) – The id of the post on which you want to add the custom field

$meta_key (required) – The name(or key) of the custom field you want to add

$meta_value (required) – the value of the

Basic usage example:

A good more advanced example of using add_post_meta() will be to add a custom value to WordPress post on post publish(save_post action):

About Pavel Petrov 2 Articles |  17 How-tos

Pavel is a senior developer for the last 7 years, with extended interest in Linux administration, WordPress and Symfony.


Be the first to comment

Leave a Reply

Your email address will not be published.


*