tp TouchPointWP Taxonomies - TenthPres/TouchPoint-WP GitHub Wiki

tp\TouchPointWP\Taxonomies

Everything related to the plugin's Taxonomies.


  • Full name: \tp\TouchPointWP\Taxonomies
  • This class is an Abstract class

Constants

Constant Visibility Type Value
TAX_TENSE_PRESENT public "present"
TAX_INV_MARITAL public \tp\TouchPointWP\TouchPointWP::HOOK_PREFIX . "inv_marital"
TAX_TENSE_PAST public "past"
TAX_DIV public \tp\TouchPointWP\TouchPointWP::HOOK_PREFIX . "div"
TAX_AGEGROUP public \tp\TouchPointWP\TouchPointWP::HOOK_PREFIX . "agegroup"
TAX_RESCODE public \tp\TouchPointWP\TouchPointWP::HOOK_PREFIX . "rescode"
TAX_CAMPUS public \tp\TouchPointWP\TouchPointWP::HOOK_PREFIX . "campus"
TAX_GP_CATEGORY public \tp\TouchPointWP\TouchPointWP::HOOK_PREFIX . "partner_category"
TAX_WEEKDAY public \tp\TouchPointWP\TouchPointWP::HOOK_PREFIX . "weekday"
TAX_TENSE_FUTURE public "future"
TAX_DAYTIME public \tp\TouchPointWP\TouchPointWP::HOOK_PREFIX . "timeofday"
TAX_TENSE public \tp\TouchPointWP\TouchPointWP::HOOK_PREFIX . "tense"
TAXMETA_LOOKUP_ID public \tp\TouchPointWP\TouchPointWP::HOOK_PREFIX . "lookup_id"

Properties

forceTermLookupIdUpdate

public static bool $forceTermLookupIdUpdate
  • This property is static.

Methods

insertTermsForArrayBasedTaxonomy

For the taxonomies that are based on Lookups in the TouchPoint database, insert or update the terms. Also removes any items that are no longer present in the list.

public static insertTermsForArrayBasedTaxonomy(string[] $list, string $taxonomy, bool $forceIdUpdate): void
  • This method is static. Parameters:
Parameter Type Description
$list string[] where the slug is the key and the name is the value.
$taxonomy string
$forceIdUpdate bool

insertTermsForLookupBasedTaxonomy

For the taxonomies that are based on Lookups in the TouchPoint database, insert or update the terms. Also removes any items that are no longer present in the list.

public static insertTermsForLookupBasedTaxonomy(object[] $list, string $taxonomy, bool $forceIdUpdate): void
  • This method is static. Parameters:
Parameter Type Description
$list object[]
$taxonomy string
$forceIdUpdate bool

getTaxTermId

Get the term id for a given taxonomy and value.

public static getTaxTermId(mixed $taxonomy, mixed $value): ?int
  • This method is static. Parameters:
Parameter Type Description
$taxonomy mixed string Taxonomy name
$value mixed int|string The Lookup ID or name or slug of the term.

getTermsClauses

Filter to add a tp_post_type option to get_terms that takes either a string of one post type or an array of post types.

public static getTermsClauses(mixed $clauses, mixed $taxonomy, mixed $args): mixed
  • This method is static. Parameters:
Parameter Type Description
$clauses mixed
$taxonomy mixed
$args mixed

Hat tip https://dfactory.eu/wp-how-to-get-terms-post-type/ |


insertTerms

Insert the terms for the registered taxonomies. (This is supposed to happen a while after the taxonomies are loaded.)

public static insertTerms(?\tp\TouchPointWP\TouchPointWP|string $instance = null): void
  • This method is static. Parameters:
Parameter Type Description
$instance ?\tp\TouchPointWP\TouchPointWP|string Default value for init call may be null or ''.

termExists

Wrapper for the WordPress term_exists function to reduce database calls

public static termExists(int|string $term, string $taxonomy = "", int|null $parent = null): mixed
  • This method is static. Parameters:
Parameter Type Description
$term int|string The term to check. Accepts term ID, slug, or name.
$taxonomy string Optional. The taxonomy name to use.
$parent int|null Optional. ID of parent term under which to confine the exists search.

Return Value:

Returns null if the term does not exist. Returns the term ID if no taxonomy is specified and the term ID exists. Returns an array of the term ID and the term taxonomy ID if the taxonomy is specified and the pairing exists. Returns 0 if term ID 0 is passed to the function.

See Also:

  • \tp\TouchPointWP\term_exists()

insertTerm

Wrapper for the WordPress wp_insert_term function to reduce database calls

public static insertTerm(string $term, string $taxonomy, array|string $args = []): array|\WP_Error

Add a new term to the database.

A non-existent term is inserted in the following sequence:

  1. The term is added to the term table, then related to the taxonomy.
  2. If everything is correct, several actions are fired.
  3. The 'term_id_filter' is evaluated.
  4. The term cache is cleaned.
  5. Several more actions are fired.
  6. An array is returned containing the term_id and term_taxonomy_id.

If the 'slug' argument is not empty, then it is checked to see if the term is invalid. If it is not a valid, existing term, it is added and the term_id is given.

If the taxonomy is hierarchical, and the 'parent' argument is not empty, the term is inserted and the term_id will be given.

Error handling: If $taxonomy does not exist or $term is empty, a WP_Error object will be returned.

If the term already exists on the same hierarchical level, or the term slug and name are not unique, a WP_Error object will be returned.

  • This method is static. Parameters:
Parameter Type Description
$term string The term name to add.
$taxonomy string The taxonomy to which to add the term.
$args array|string {
Optional. Array or query string of arguments for inserting a term.

Return Value:

{ An array of the new term data, WP_Error otherwise.

See Also:

  • \tp\TouchPointWP\wp_insert_term()

registerTaxonomies

Register the taxonomies.

public static registerTaxonomies(\tp\TouchPointWP\TouchPointWP $instance): void
  • This method is static. Parameters:
Parameter Type Description
$instance \tp\TouchPointWP\TouchPointWP