2014-03-04 200 views
0

我有一種稱爲資源的帖子類型,這種帖子類型中的分類稱爲category,然後我有標籤..我需要獲取此帖子類型中標籤的ID。 。這是我迄今爲止..與此問題是get_term_children()需要一個ID,我不想具體的ID,但所有的ID ..這些變量將傳遞給我的AJAX ..請幫助如何獲得帖子類型的標籤ID

$tag_id = array(); 
     $tag_resource = get_term_children('', 'category'); 
     foreach ($tag_resource as $child_location) { 
       $tag_term = get_term_by('id', $child_location, 'post_tag'); 
       $tag_id[] = $tag_term->term_id; 
      } 

回答

0

您可以使用下面函數來獲取條款ID

function get_terms_id_by_post_type($taxonomies, $post_types) { 
    global $wpdb; 
    $query = $wpdb->get_col("SELECT t.term_id from $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id INNER JOIN $wpdb->term_relationships AS r ON r.term_taxonomy_id = tt.term_taxonomy_id INNER JOIN $wpdb->posts AS p ON p.ID = r.object_id WHERE p.post_type IN('" . join("', '", $post_types) . "') AND tt.taxonomy IN('" . join("', '", $taxonomies) . "') GROUP BY t.term_id"); 
    return $query; 
} 
相關問題