$meta
$meta :
__construct(\TriTan\Interfaces\MetaDataInterface $meta, \TriTan\Interfaces\UtilsInterface $util)
\TriTan\Interfaces\MetaDataInterface | $meta | |
\TriTan\Interfaces\UtilsInterface | $util |
create(integer $post_id, string $meta_key, mixed $meta_value, boolean $unique = false) : integer|false
Add meta data field to a post.
integer | $post_id | Post ID. |
string | $meta_key | Metadata name. |
mixed | $meta_value | Metadata value. Must be serializable if non-scalar. |
boolean | $unique | Optional. Whether the same key should not be added. Default false. |
Meta ID on success, false on failure.
read(integer $post_id, string $key = '', boolean $single = false) : mixed
Retrieve post meta field for a post.
integer | $post_id | Post ID. |
string | $key | Optional. The meta key to retrieve. By default, returns data for all keys. Default empty. |
boolean | $single | Optional. Whether to return a single value. Default false. |
Will be an array if $single is false. Will be value of meta data field if $single is true.
update(integer $post_id, string $meta_key, mixed $meta_value, mixed $prev_value = '') : integer|boolean
Update post meta field based on post ID.
Use the $prev_value parameter to differentiate between meta fields with the same key and post ID.
If the meta field for the post does not exist, it will be added.
integer | $post_id | Post ID. |
string | $meta_key | Metadata key. |
mixed | $meta_value | Metadata value. Must be serializable if non-scalar. |
mixed | $prev_value | Optional. Previous value to check before removing. Default empty. |
Meta ID if the key didn't exist, true on successful update, false on failure.
delete(integer $post_id, string $meta_key, mixed $meta_value = '') : boolean
Remove metadata matching criteria from a post.
You can match based on the key, or key and value. Removing based on key and value, will keep from removing duplicate metadata with the same key. It also allows removing all metadata matching key, if needed.
integer | $post_id | Post ID. |
string | $meta_key | Metadata name. |
mixed | $meta_value | Optional. Metadata value. Must be serializable if non-scalar. Default empty. |
True on success, false on failure.