2017-04-18 15 views
0

私はカスタムポストタイプのタクソノミ用語を表示しようとしています(普通の投稿では<?php the_category(' '); ?>を使用しています)。下のコードは機能しますが、分類名を指定する必要があります。投稿IDのみを使用する方法はありますか?分類法名なしのタクソノミー用語を取得する

<?php 

    $terms = get_the_terms($post->ID , 'taxonomy_name'); 
    foreach ($terms as $term) { 
    echo $term->name; 
    } 
?> 

ありがとうございます!

答えて

0
<?php print the_terms($post->ID, 'taxonomy_name' , ' '); ?> 

分類法名を持たないカスタムタクソミー用語を得ることはできませんが、上記のコードはそれよりも短くなります。

+0

こんにちは@Gazi、回答ありがとうございます。私はそれを行う方法を見つけた。これをforeachループの前に使う:$ cat = get_post_taxonomies($ post); $ terms = get_the_terms($ post-> ID、$ cat [1]); –

0

私はそれを行う方法を見つけました。 「get_post_taxonomies」を使用して、配列の魔女猫を選択すると、[1]

<?php 

$cat = get_post_taxonomies($post); 
$terms = get_the_terms($post->ID , $cat[1]); 

// Loop 
if ($terms != null){ 

    foreach($terms as $term) { 
    $term_link = get_term_link($term, $cat[1]); 

    // Print the name and URL 
    echo '<a href="' . $term_link . '">' . $term->name . '</a>'; 

    unset($term); } } 

?> 
0

これを試してみてください。、

あなたは用語の詳細を取得することはできません分類なし分類法を使用する必要があります。

ありがとう!

関連する問題