Php 如何获取post类型的标签id

Php 如何获取post类型的标签id,php,arrays,wordpress,Php,Arrays,Wordpress,我有一个名为resource的帖子类型,这个帖子类型中的分类法名为category,然后我有标签。。我需要获取此帖子类型中标签的ID。。这就是我到目前为止所拥有的。。问题是get_term_children()需要一个id,我不需要特定的id,但需要所有的id。。这些变量将被传递到我的ajax。。请帮忙 $tag_id = array(); $tag_resource = get_term_children( '', 'category' ); foreach (

我有一个名为resource的帖子类型,这个帖子类型中的分类法名为category,然后我有标签。。我需要获取此帖子类型中标签的ID。。这就是我到目前为止所拥有的。。问题是get_term_children()需要一个id,我不需要特定的id,但需要所有的id。。这些变量将被传递到我的ajax。。请帮忙

$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;
            }

您可以使用下面的函数获取术语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;
}