万が一、当サイトで重大な問題を発見した際などは、フォーラムや WordSlack #docs チャンネルでお知らせください。</p>
関数リファレンス/term exists
目次
説明
指定されたターム(タクソノミーの項目)が存在するかチェックし、タームの ID か、タームの配列を返します。 存在しない場合は 0 (false) を返します。
使い方
<?php term_exists( $term, $taxonomy, $parent ) ?>
パラメータ
- $term
- (整数|文字列) (必須) チェックするターム
- 初期値: なし
- $taxonomy
- (文字列) (オプション) タクソノミーの名前
- 初期値: ''
- $parent
- (整数) (オプション) 親のターム ID を指定すると、その子タームに限定してタームの有無をチェックする
- 初期値: 0
戻り値
- (mixed)
-
- タームが存在しなければ 0 または NULL を返す。
- タクソノミーが指定されず、タームが存在する場合、ターム ID を返す。
- タクソノミーとタームのペアが存在する場合、配列を返す。(形式は array('term_id'=>ターム ID, 'term_taxonomy_id'=>タクソノミー ID) )
例
'Uncategorized' というカテゴリーの有無をチェック
<?php $term = term_exists('Uncategorized', 'category'); if ($term !== 0 && $term !== null) { echo "'Uncategorized' カテゴリーがあります!"; } ?>
'Untagged' という投稿タグの有無をチェック
<?php $term = term_exists('Untagged', 'post_tag'); if ($term !== 0 && $term !== null) { echo "'Untagged' 投稿タグがあります!"; } ?>
参考
- グローバル変数 (object) $wpdb を使用。
改訂履歴
3.0 以降。
ソースファイル
term_exists() は wp-includes/taxonomy.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/term_exists (最新版との差分)