- 赤色のリンクは、まだ日本語Codexに存在しないページ・画像です。英語版と併せてご覧ください。(詳細)
関数リファレンス/has term
現在の投稿(または指定された投稿)が指定されたタームを持っているかチェックします。
指定されたタームは、投稿に付けられたタームの ID、名前、スラッグに合うかチェックされます。 整数で指定されたタームは、投稿のタームの ID のみと比較されます。
タームが指定されない場合は、投稿が任意のタームを持つかチェックします。
使い方
<?php has_term( $term, $taxonomy, $post ) ?>
パラメータ
- $term
- (文字列|整数|配列) (オプション) チェックするタームの名前、ID、スラッグ、またはそれらの配列。
- 初期値: ''
- $taxonomy
- (文字列) (必須) タクソノミーの名前
- 初期値: なし
- $post
- (整数|オブジェクト) (オプション) チェックする投稿の ID または投稿オブジェクト。
- 初期値: null - 現在の投稿
戻り値
- (真偽値)
- 指定されたタームの何れかを(タームが指定されなかった場合は、任意のタームを)投稿が持っていれば
true
を返す。
用例
if( has_term( 'jazz', 'genre' ) ) { // カスタム分類 genre のターム jazz が付いている投稿 }
参考
変更履歴
- 3.1.0 : 新規導入。
ソースファイル
has_term() は /wp-includes/category-template.php
にあります。
関連項目
タームタグ: is_term(), term_exists(), get_objects_in_term(), get_term(), get_term_by(), get_term_children(), get_term_link(), get_terms(), get_the_terms(), get_the_term_list(), has_term(), sanitize_term(), the_terms(), get_object_taxonomies() is_object_in_taxonomy() the_taxonomies() wp_get_object_terms(), wp_set_object_terms(), wp_get_post_terms(), wp_set_post_terms(), wp_delete_object_term_relationships()
条件分岐タグ:
is_404(),
is_admin(),
is_admin_bar_showing(),
is_archive(),
is_attachment(),
is_author(),
is_category(),
is_comments_popup(),
is_date(),
is_day(),
is_feed(),
is_front_page(),
is_home(),
is_local_attachment(),
is_main_query,
/is_multi_author,
is_month(),
is_new_day(),
is_page(),
is_page_template(),
is_paged(),
is_plugin_active(),
is_plugin_active_for_network() /en,
is_plugin_inactive() /en,
is_plugin_page() /en,
is_post_type_archive(),
is_preview() /en,
is_search(),
is_single(),
is_singular(),
is_sticky(),
is_tag(),
is_tax(),
is_taxonomy_hierarchical(),
is_time(),
is_trackback(),
is_year(),
in_category(),
in_the_loop(),
is_active_sidebar(),
is_active_widget(),
is_blog_installed() /en,
is_rtl(),
is_dynamic_sidebar(),
is_user_logged_in(),
has_excerpt(),
has_post_thumbnail(),
has_tag(),
pings_open(),
email_exists(),
post_type_exists(),
taxonomy_exists(),
term_exists(),
username_exists() /en,
wp_attachment_is_image(),
wp_script_is()
最新英語版: WordPress Codex » Function Reference/has_term (最新版との差分)