class Fieldmanager_Util_Term_Meta (View source)

deprecated 1.0.0-beta.3

Use Fieldmanager to store meta data for taxonomy terms.

This is deprecated as of WordPress 4.4, which introduces term meta into core. If you were using this feature prior to 4.4, it will continue to operate until probably WordPress 4.8, however it is in your best interest to migrate your data ASAP, as core's term meta is significantly more efficient.

Methods

static object
instance()

Singleton helper

setup()

Sets up the class.

create_content_type()

Create the custom content type.

string
post_slug(int $term_id, string $taxonomy)

Get the slug (post_name and post_title) for the fm_term_meta post.

string|array
get_term_meta(int $term_id, string $taxonomy, string $meta_key = '', bool $single = false)

Get metadata matching the specified key for the given term ID/taxonomy pair.

bool|int
add_term_meta(int $term_id, string $taxonomy, string $meta_key, mixed $meta_value, bool $unique = false)

Add metadata to a term ID/taxonomy pair.

mixed
update_term_meta(int $term_id, string $taxonomy, string $meta_key, mixed $meta_value, mixed $meta_prev_value = '')

Update metadata for a term ID/taxonomy pair.

bool
delete_term_meta(int $term_id, string $taxonomy, string $meta_key, mixed $meta_value = '')

Remove metadata matching criteria from a term ID/taxonomy pair.

int|bool
get_term_meta_post_id(int $term_id, string $taxonomy)

Handles checking if post exists and returning its ID to store taxonomy term meta data.

string
get_term_meta_post_id_cache_key(int $term_id, string $taxonomy)

Generates a standardized cache key for the term meta post ID.

delete_term_meta_post_id_cache(int $term_id, string $taxonomy)

Clears the cache for a term meta post ID.

bool
add_term_meta_post(int $term_id, string $taxonomy)

Handles adding a post to store taxonomy term meta data.

collect_garbage(int $term_id, int $tt_id, string $taxonomy)

When a term is deleted, delete its ghost post and related meta.

split_shared_term(int $old_term_id, int $new_term_id, int $term_taxonomy_id, string $taxonomy)

Update term meta when a shared term gets split (as of WordPress 4.2).

Details

static object instance()

Singleton helper

Return Value

object

The singleton instance

setup()

Sets up the class.

create_content_type()

Create the custom content type.

protected string post_slug(int $term_id, string $taxonomy)

Get the slug (post_name and post_title) for the fm_term_meta post.

Parameters

int $term_id

Term ID.

string $taxonomy

Term taxonomy.

Return Value

string

Post slug.

string|array get_term_meta(int $term_id, string $taxonomy, string $meta_key = '', bool $single = false)

Get metadata matching the specified key for the given term ID/taxonomy pair.

Parameters

int $term_id

Term ID.

string $taxonomy

Taxonomy name that $term_id is part of.

string $meta_key

Metadata name.

bool $single

Optional. Get a single result or multiple.

Return Value

string|array get_post_meta().

bool|int add_term_meta(int $term_id, string $taxonomy, string $meta_key, mixed $meta_value, bool $unique = false)

Add metadata to a term ID/taxonomy pair.

Parameters

int $term_id

Term ID.

string $taxonomy

Taxonomy name that $term_id is part of.

string $meta_key

Metadata name.

mixed $meta_value

The value of the custom field which should be added. If an array is given, it will be serialized into a string.

bool $unique

Optional. Whether or not you want the key to stay unique. When set to true, the custom field will not be added if the given key already exists among custom fields of the specified post.

Return Value

bool|int add_post_meta().

mixed update_term_meta(int $term_id, string $taxonomy, string $meta_key, mixed $meta_value, mixed $meta_prev_value = '')

Update metadata for a term ID/taxonomy pair.

Use the $prev_value parameter to differentiate between meta fields with the same key and post ID.

If the meta field for the term does not exist, it will be added.

Parameters

int $term_id

Term ID.

string $taxonomy

Taxonomy name that $term_id is part of.

string $meta_key

Metadata name.

mixed $meta_value

The new value of the custom field. A passed array will be serialized into a string.

mixed $meta_prev_value

Optional. The old value of the custom field you wish to change. This is to differentiate between several fields with the same key. If omitted, and there are multiple rows for this post and meta key, all meta values will be updated.

Return Value

mixed update_post_meta().

bool delete_term_meta(int $term_id, string $taxonomy, string $meta_key, mixed $meta_value = '')

Remove metadata matching criteria from a term ID/taxonomy pair.

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

int $term_id

Term ID.

string $taxonomy

Taxonomy name that $term_id is part of.

string $meta_key

Metadata name.

mixed $meta_value

Optional. The value of the field you will delete. This is used to differentiate between several fields with the same key. If left blank, all fields with the given key will be deleted.

Return Value

bool

False for failure. True for success.

int|bool get_term_meta_post_id(int $term_id, string $taxonomy)

Handles checking if post exists and returning its ID to store taxonomy term meta data.

Parameters

int $term_id

Term ID.

string $taxonomy

Term taxonomy.

Return Value

int|bool

Post ID or false.

string get_term_meta_post_id_cache_key(int $term_id, string $taxonomy)

Generates a standardized cache key for the term meta post ID.

Parameters

int $term_id

Term ID.

string $taxonomy

Term taxonomy.

Return Value

string

Cache key.

delete_term_meta_post_id_cache(int $term_id, string $taxonomy)

Clears the cache for a term meta post ID.

Parameters

int $term_id

Term ID.

string $taxonomy

Term taxonomy.

bool add_term_meta_post(int $term_id, string $taxonomy)

Handles adding a post to store taxonomy term meta data.

Parameters

int $term_id

Term ID.

string $taxonomy

Term taxonomy.

Return Value

bool

collect_garbage(int $term_id, int $tt_id, string $taxonomy)

When a term is deleted, delete its ghost post and related meta.

Parameters

int $term_id

Term ID.

int $tt_id

Term taxonomy ID.

string $taxonomy

Term taxonomy.

split_shared_term(int $old_term_id, int $new_term_id, int $term_taxonomy_id, string $taxonomy)

Update term meta when a shared term gets split (as of WordPress 4.2).

Parameters

int $old_term_id

The pre-split (previously shared) term ID.

int $new_term_id

The post-split term ID.

int $term_taxonomy_id

The term_taxonomy_id for this term. Note that this doesn't change when a shared term is split (since it's already unique).

string $taxonomy

The taxonomy of the split term.