\TriTan\Common\PostPostMetaData

Summary

Methods
Properties
Constants
__construct()
create()
read()
update()
delete()
readByMid()
updateByMid()
deleteByMid()
$meta
$util
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Properties

$meta

$meta : 

Type

$util

$util : 

Type

Methods

create()

create(integer  $post_id, string  $meta_key, mixed  $meta_value, boolean  $unique = false) : integer|false

Add meta data field to a post.

Parameters

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.

Returns

integer|false —

Meta ID on success, false on failure.

read()

read(integer  $post_id, string  $key = '', boolean  $single = false) : mixed

Retrieve post meta field for a post.

Parameters

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.

Returns

mixed —

Will be an array if $single is false. Will be value of meta data field if $single is true.

update()

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.

Parameters

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.

Returns

integer|boolean —

Meta ID if the key didn't exist, true on successful update, false on failure.

delete()

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.

Parameters

integer $post_id

Post ID.

string $meta_key

Metadata name.

mixed $meta_value

Optional. Metadata value. Must be serializable if non-scalar. Default empty.

Returns

boolean —

True on success, false on failure.

readByMid()

readByMid(integer  $mid) : array|boolean

Get post meta data by meta ID.

Parameters

integer $mid

Meta id.

Returns

array|boolean

updateByMid()

updateByMid(integer  $mid, string  $meta_key, string  $meta_value) : boolean

Update post meta data by meta ID.

Parameters

integer $mid
string $meta_key

Meta key.

string $meta_value

Meta value.

Returns

boolean

deleteByMid()

deleteByMid(integer  $mid) : boolean

Delete post meta data by meta ID.

Parameters

integer $mid

Meta id.

Returns

boolean