当サイト、Codex 日本語版は今後積極的な更新は行わない予定です。後継となる新ユーザーマニュアルは、https://ja.wordpress.org/support/ にあります。
万が一、当サイトで重大な問題を発見した際などは、フォーラムWordSlack #docs チャンネルでお知らせください。</p>

関数リファレンス/get term link

提供: WordPress Codex 日本語版
< 関数リファレンス
2014年7月21日 (月) 22:06時点におけるGblsm (トーク | 投稿記録)による版 (en:Function Reference/get term link 14:08, 9 July 2014 Jdgrimes 版を流し込み。)

(差分) ← 古い版 | 最新版 (差分) | 新しい版 → (差分)
移動先: 案内検索

このページ「関数リファレンス/get term link」は未翻訳です。和訳や日本語情報を加筆してくださる協力者を求めています

Description

Returns permalink for a taxonomy term archive, or a WP_Error object if the term does not exist.

Usage

<?php get_term_link( $term, $taxonomy ); ?>

Parameters

$term
object/int/string) (必須) The term object / term ID / term slug whose link will be retrieved.
初期値: なし
$taxonomy
string) (optional) The taxonomy slug. Optional when $term is an object.
初期値: empty string

Return Values

URL (string) 
URL to taxonomy term archive.
WP_Error (object) 
Error if term does not exist.

Examples

$terms = get_terms( 'species' );

echo '<ul>';

foreach ( $terms as $term ) {

    // The $term is an object, so we don't need to specify the $taxonomy.
    $term_link = get_term_link( $term );
   
    // If there was an error, continue to the next term.
    if ( is_wp_error( $term_link ) ) {
        continue;
    }

    // We successfully got a link. Print it out.
    echo '<li><a href="' . esc_url( $term_link ) . '">' . $term->name . '</a></li>';
}

echo '</ul>';

Notes

  • Uses: apply_filters() Calls 'term_link' filter on the finished link.
  • Uses global: (WP_Rewrite) $wp_rewrite
  • Since the term can be an object, integer, or string, make sure that any numbers you pass in are explicitly converted to an integer (example: (int) $term_id). Otherwise the function will assume that $term is a slug instead of a term ID.
  • Because of the above, $term->term_id doesn't work for the $term parameter prior to 3.8.0. See this trac ticket for more info.
  • PHP may halt if you attempt to print an error result ("Catchable fatal error: Object of class WP_Error could not be converted to string"). You should always use is_wp_error() to check the result of this function, in case the term does not exist.

Change Log

  • 3.1.0: $taxonomy is optional when passing a term object. It is still required if $term is passed as a string. See ticket #13081.
  • Since: 2.5.0

Source File

get_term_link() is located in wp-includes/taxonomy.php.

Related

カテゴリータグ: the_category(), the_category_rss(), single_cat_title(), category_description(), wp_dropdown_categories(), wp_list_categories(), get_the_category(), get_the_category_by_ID(), get_category_by_slug(), get_the_category_list(), get_category_parents(), get_category_link(), is_category(), in_category()


タームタグ: 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()



関数リファレンステンプレートタグ目次もご覧ください。


最新英語版: WordPress Codex » Function Reference/get term link最新版との差分