# Store Custom Data

### 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.

{% content-ref url="store-custom-data/posts" %}
[posts](https://docs.minical.io/build-an-extension/store-custom-data/posts)
{% endcontent-ref %}

{% content-ref url="store-custom-data/postmeta" %}
[postmeta](https://docs.minical.io/build-an-extension/store-custom-data/postmeta)
{% endcontent-ref %}

### 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.

{% content-ref url="store-custom-data/options" %}
[options](https://docs.minical.io/build-an-extension/store-custom-data/options)
{% endcontent-ref %}

| Method             | Description                | Parameters Description                                                                                                                                                                                                                                                                                                                                                                                                                                            | Return value                                                                                                                                               |
| ------------------ | -------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |
| add\_option()      | Adds a new option value.   | <p><strong>add\_option(string $option, $value = '', bool $autoload = true)</strong><br><br><strong>1.</strong> string $option (Required) Name of the option to add.<br><strong>2.</strong> mixed $value (Optional) Option value.<br><strong>3.</strong> bool $autoload (Optional) Whether to load the option when extension starts up. Default is enabled.<br></p>                                                                                                | <p><strong>bool</strong><br>True if the option was added, null otherwise.</p>                                                                              |
| get\_option()      | Get option value.          | <p><strong>get\_option( string $option, bool $default = false)</strong><br><br><strong>1.</strong> string $option (Required) Name of the option to add.<br><strong>2.</strong> bool $default (Optional) Default value to return if the option does not exist.<br></p>                                                                                                                                                                                             | <p><strong>bool</strong><br>Value of the option. A value of any type may be returned, If there is no option in the database, boolean false is returned</p> |
| update\_option()   | Update option value.       | <p><strong>update\_option( string $option, $value = '', bool $autoload = true )</strong><br><br><strong>1.</strong> string $option (Required) Name of the option to update.<br><strong>2.</strong> mixed $value (Required) Option value.<br><strong>3.</strong> bool $autoload (Optional) Whether to load the option when extension starts up. Default is enabled.<br></p>                                                                                        | <p><strong>bool</strong><br>True if the value was updated, false otherwise.</p>                                                                            |
| delete\_option()   | delete option value.       | <p><strong>delete\_option( string $option )</strong><br><br><strong>1.</strong> string $option (Required) Name of the option to delete.</p>                                                                                                                                                                                                                                                                                                                       | <p><strong>bool</strong><br>True if the option was deleted, false otherwise.</p>                                                                           |
| add\_post\_meta()  | Adds a new postmeta value. | <p><strong>add\_post\_meta ($post\_id, $key, $value)</strong><br><br><strong>1.</strong> int $post\_id (Required) The id of the post corresponds to the postmeta data.<br><strong>2.</strong> string $key (Required) The meta key.<br><strong>3.</strong> mixed $value (Required) The meta value to the corresponding key.<br></p>                                                                                                                                | <p><strong>null</strong><br></p>                                                                                                                           |
| get\_postmeta()    | Get postmeta value.        | <p><strong>get\_post\_meta(int $post\_id = null, string $key = null, bool $single = false )</strong><br><br><strong>1.</strong> int $post\_id The id of the post corresponds to the postmeta data.<br><strong>2.</strong> string $key Optional, The meta key to retrieve. By default, returns data for all keys.<br><strong>3.</strong> boolean $single Optional Whether to return a single value. This parameter has no effect if $key is not specified.<br></p> | <p><strong>mixed</strong><br>Either array or null, if postmeta data is available or no error occurs, then array else null.</p>                             |
| update\_postmeta() | Update postmeta value.     | <p><strong>update\_post\_meta(array $post\_meta = null, int $post\_id = null)</strong><br><br><strong>1.</strong> array $post\_meta An array of postmeta data to be updated.<br><strong>2.</strong> int $post\_id The id of the post corresponds to the postmeta data.<br></p>                                                                                                                                                                                    | <p><strong>mixed</strong><br>Either true or null, if postmeta data is updated then true else null.</p>                                                     |
| detele\_postmeta() | Detele postmeta value.     | <p><strong>delete\_post\_meta(int $post\_id = null, string $meta\_key = null, $meta\_value = null)</strong><br><br><strong>1.</strong> int $post\_id The id of the post corresponds to the postmeta data.<br><strong>2.</strong> string $meta\_key name of key.<br><strong>3.</strong> mixed $meta\_value value of key this will make delete more certain (in case key name is same).<br></p>                                                                     | <p><strong>mixed</strong><br>Either true or null, if postmeta data is deleted then true else null.</p>                                                     |
| add\_post()        | Adds a new post value.     | <p><strong>add\_post ($data)</strong><br><br><strong>1.</strong> array $data the data array of post.</p>                                                                                                                                                                                                                                                                                                                                                          | <p><strong>null</strong><br></p>                                                                                                                           |
| get\_post()        | Get post value.            | <p><strong>get\_post( $post )</strong><br><br><strong>1.</strong> mixed $post Int id of post or An Array of post data, this key will be added in where clause.</p>                                                                                                                                                                                                                                                                                                | <p><strong>mixed</strong><br>Either array or null, if post data is available or no error occurs, then array else null.</p>                                 |
| edit\_post()       | Update post value.         | <p><strong>edit\_post(array $post = null)</strong><br><br><strong>1.</strong> array $post An Array of post data including post\_id.</p>                                                                                                                                                                                                                                                                                                                           | <p><strong>mixed</strong><br>Either post\_id or null, if post data is updated or no error occurs, then id else null.</p>                                   |
| detele\_post()     | Detele post value.         | <p><strong>delete\_post(int $post\_id = null, bool $force\_delete = false )</strong><br><br><strong>1.</strong> int $post\_id The id of the post. <strong>2.</strong> bool $force\_delete flag to force delete a post, default is false..</p>                                                                                                                                                                                                                     | <p><strong>mixed</strong><br>Either true or null, if postmeta data is delete then true else null.</p>                                                      |
