has_term_meta()
Gets all metadata of the specified taxonomy element (term).
The data contain meta field ID, term ID, meta key and value.
This function gets data from database directly, without any caching.
1 time — 0.001984 sec (very slow) | 50000 times — 11.92 sec (slow) | PHP 7.1.5, WP 4.9
No Hooks.
Return
Array|false
. Array with meta data, or false when the meta table is not installed.
Usage
has_term_meta( $term_id );
- $term_id(int) (required)
- Term ID.
Examples
#1 Get all metadata of term 33
This example shows the format of the returned data.
print_r( has_term_meta(33) ); /* Array ( [0] => Array ( [meta_key] => _views_prev_month_up [meta_value] => 1510839874 [meta_id] => 663 [term_id] => 33 ) [1] => Array ( [meta_key] => views [meta_value] => 2417 [meta_id] => 20 [term_id] => 33 ) [2] => Array ( [meta_key] => views_prev_month [meta_value] => 158 [meta_id] => 664 [term_id] => 33 ) ) */
Notes
- Global. wpdb. $wpdb WordPress database abstraction object.
Changelog
Since 4.9.0 | Introduced. |
has_term_meta() has term meta code WP 6.7.1
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 ); }