2012-09-05 84 views

回答

202

沒關係!我發現它:)

get_queried_object()->term_id; 
+4

太好了!這節省了我很多時間:D – MavBzh

+0

真的,非常感謝... – aidadev

+0

非常感謝! –

31

下面是需要整個代碼片段:

$queried_object = get_queried_object(); 
$term_id = $queried_object->term_id; 
3
<?php 
$terms = get_the_terms($post->ID, 'taxonomy'); 
foreach ($terms as $term) { 
    $termID[] = $term->term_id; 
} 
echo $termID[0]; 
?> 
1

wp_get_post_terms(),你會做像這樣的東西:

global $post; 
$terms = wp_get_post_terms($post->ID, 'YOUR_TAXONOMY_NAME',array('fields' => 'ids')); 

print_r($terms); 
0

這是術語塞你want.Looks喜歡,你可以得到這樣的ID,如果這就是你需要:

function get_term_link($term, $taxonomy = '') { 
    global $wp_rewrite; 

    if (!is_object($term)) { 
     if (is_int($term)) { 
      $term = get_term($term, $taxonomy); 
     } else { 
      $term = get_term_by('slug', $term, $taxonomy); 
     } 
    } 
2

請複製下面的代碼粘貼!

這將打印當前的分類名稱和描述(可選)

<?php 
    $tax = $wp_query->get_queried_object(); 
    echo ''. $tax->name . ''; 
    echo "<br>"; 
    echo ''. $tax->description .''; 
?> 
相關問題