Summery Summery
Determines whether a taxonomy term exists.
Syntax Syntax
Description Description
Formerly is_term(), introduced in 2.3.0.
For more information on this and similar theme functions, check out the Conditional Tags article in the Theme Developer Handbook.
Parameters Parameters
- $term
-
(Required) The term to check. Accepts term ID, slug, or name.
- $taxonomy
-
(Optional) The taxonomy name to use.
Default value: ''
- $parent
-
(Optional) ID of parent term under which to confine the exists search.
Default value: null
Return Return
(mixed) 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.
Source Source
File: wp-includes/taxonomy.php
* to register the meta key across all existing taxonomies. * @param string $meta_key The meta key to register. * @param array $args Data used to describe the meta key when registered. See * {@see register_meta()} for a list of supported arguments. * @return bool True if the meta key was successfully registered, false if not. */ function register_term_meta( $taxonomy, $meta_key, array $args ) { $args['object_subtype'] = $taxonomy; return register_meta( 'term', $meta_key, $args ); } /** * Unregisters a meta key for terms. * * @since 4.9.8 * * @param string $taxonomy Taxonomy the meta key is currently registered for. Pass * an empty string if the meta key is registered across all * existing taxonomies. * @param string $meta_key The meta key to unregister. * @return bool True on success, false if the meta key was not previously registered. */ function unregister_term_meta( $taxonomy, $meta_key ) { return unregister_meta_key( 'term', $meta_key, $taxonomy ); } /** * Determines whether a taxonomy term exists. * * Formerly is_term(), introduced in 2.3.0. * * For more information on this and similar theme functions, check out * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ * Conditional Tags} article in the Theme Developer Handbook. * * @since 3.0.0 * * @global wpdb $wpdb WordPress database abstraction object. * * @param int|string $term The term to check. Accepts term ID, slug, or name. * @param string $taxonomy Optional. The taxonomy name to use. * @param int $parent Optional. ID of parent term under which to confine the exists search. * @return mixed 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. */ function term_exists( $term, $taxonomy = '', $parent = null ) { global $wpdb; $select = "SELECT term_id FROM $wpdb->terms as t WHERE "; $tax_select = "SELECT tt.term_id, tt.term_taxonomy_id FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy as tt ON tt.term_id = t.term_id WHERE "; if ( is_int( $term ) ) { if ( 0 === $term ) { return 0;
Advertisement
Changelog Changelog
Version | Description |
---|---|
3.0.0 | Introduced. |