Metadata can be described as data about data. Postmeta is the way to store post-related metadata that has an impact on a post. All the data is stored in the postmeta table and mapped with the post_id.
- For posts, post_type is an example of metadata, but it's stored in the posts table
- Taxonomy terms, categories, and tags can also be loosely defined as metadata, but these are stored entirely separately, in their own database tables.
- Post metadata such as custom fields and additional metadata added via extension is stored in the postmeta table, as you would expect.
So it's easier to think of metadata in miniCal not according to the strict definition of the term, but as the data stored in the three metadata tables.
- Metadata about the extension.
- Custom Fields.
- User Metadata.
post_id=> //post id
post_key=> // key
post_value=> // value
You can add postmeta data with post data, Just add an array with key name meta. Here is an example is given.
$post = array(
'company_id' => $this->company_id,
'user_id' => $this->user_id,
'post_title' => 'Book',
'post_type' => 'self-help-book',
'post_date' => date('Y-m-d H:i:s'),
'meta' => array(
'author' => 'James Clear',
'book_name' => 'Atomic Habits',
'pages' => '290'
// Adds meta values to the database
add_post_meta ($post_id, $key, $value);
// to get postmeta data from postmeta table by post_id or meta_key.
get_post_meta(int $post_id = null, string $key = null, bool $single = false );
// update postmeta data. in the array, if a new value pass then added else update.
update_post_meta(array $post_meta = null, int $post_id = null);
//delete a postmeta data.
delete_post_meta(int $post_id = null, string $meta_key = null, $meta_value = null);