Store Custom Data

Store custom data for an extension

Understanding and Working With the miniCal POST and POST-META Tables

Suppose you are building an extension that requires a database to save the extension specify info. For instance, you need to capture username and mail-id so these details will go on the "post" and "post-meta" tables.

POSTSPOSTMETA

Understanding and Working With the miniCal OPTIONS Table

The options table stores a different kind of data from the other tables: instead of storing data about your extension content, it stores data about the application itself. miniCal provides a set of functions to add, update and delete data from this table. You can add values to existing options and you can also add new records to the table when you want to create new options.

OPTIONS

MethodDescriptionParameters DescriptionReturn value

add_option()

Adds a new option value.

add_option(string $option, $value = '', bool $autoload = true) 1. string $option (Required) Name of the option to add. 2. mixed $value (Optional) Option value. 3. bool $autoload (Optional) Whether to load the option when extension starts up. Default is enabled.

bool True if the option was added, null otherwise.

get_option()

Get option value.

get_option( string $option, bool $default = false) 1. string $option (Required) Name of the option to add. 2. bool $default (Optional) Default value to return if the option does not exist.

bool Value of the option. A value of any type may be returned, If there is no option in the database, boolean false is returned

update_option()

Update option value.

update_option( string $option, $value = '', bool $autoload = true ) 1. string $option (Required) Name of the option to update. 2. mixed $value (Required) Option value. 3. bool $autoload (Optional) Whether to load the option when extension starts up. Default is enabled.

bool True if the value was updated, false otherwise.

delete_option()

delete option value.

delete_option( string $option ) 1. string $option (Required) Name of the option to delete.

bool True if the option was deleted, false otherwise.

add_post_meta()

Adds a new postmeta value.

add_post_meta ($post_id, $key, $value) 1. int $post_id (Required) The id of the post corresponds to the postmeta data. 2. string $key (Required) The meta key. 3. mixed $value (Required) The meta value to the corresponding key.

null

get_postmeta()

Get postmeta value.

get_post_meta(int $post_id = null, string $key = null, bool $single = false ) 1. int $post_id The id of the post corresponds to the postmeta data. 2. string $key Optional, The meta key to retrieve. By default, returns data for all keys. 3. boolean $single Optional Whether to return a single value. This parameter has no effect if $key is not specified.

mixed Either array or null, if postmeta data is available or no error occurs, then array else null.

update_postmeta()

Update postmeta value.

update_post_meta(array $post_meta = null, int $post_id = null) 1. array $post_meta An array of postmeta data to be updated. 2. int $post_id The id of the post corresponds to the postmeta data.

mixed Either true or null, if postmeta data is updated then true else null.

detele_postmeta()

Detele postmeta value.

delete_post_meta(int $post_id = null, string $meta_key = null, $meta_value = null) 1. int $post_id The id of the post corresponds to the postmeta data. 2. string $meta_key name of key. 3. mixed $meta_value value of key this will make delete more certain (in case key name is same).

mixed Either true or null, if postmeta data is deleted then true else null.

add_post()

Adds a new post value.

add_post ($data) 1. array $data the data array of post.

null

get_post()

Get post value.

get_post( $post ) 1. mixed $post Int id of post or An Array of post data, this key will be added in where clause.

mixed Either array or null, if post data is available or no error occurs, then array else null.

edit_post()

Update post value.

edit_post(array $post = null) 1. array $post An Array of post data including post_id.

mixed Either post_id or null, if post data is updated or no error occurs, then id else null.

detele_post()

Detele post value.

delete_post(int $post_id = null, bool $force_delete = false ) 1. int $post_id The id of the post. 2. bool $force_delete flag to force delete a post, default is false..

mixed Either true or null, if postmeta data is delete then true else null.

Last updated