has_term_meta() WordPress Function

The has_term_meta() function allows you to check if a term has any metadata associated with it. This can be useful for checking if a term has a custom description, or if a term has been assigned a certain color.

has_term_meta( int $term_id ) #

Gets all meta data, including meta IDs, for the given term ID.


Parameters

$term_id

(int)(Required)Term ID.


Top ↑

Return

(array|false) Array with meta data, or false when the meta table is not installed.


Top ↑

Source

File: wp-includes/taxonomy.php

function has_term_meta( $term_id ) {
	$check = wp_check_term_meta_support_prefilter( null );
	if ( null !== $check ) {
		return $check;
	}

	global $wpdb;

	return $wpdb->get_results( $wpdb->prepare( "SELECT meta_key, meta_value, meta_id, term_id FROM $wpdb->termmeta WHERE term_id = %d ORDER BY meta_key,meta_id", $term_id ), ARRAY_A );
}


Top ↑

Changelog

Changelog
VersionDescription
4.9.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More
Show More