如何获得帖子类型的标签ID

时间:2014-03-04 11:32:07

标签: php arrays wordpress

我有一个名为resource的帖子类型,在这个帖子类型中称为类别的分类法,然后我有标签..我需要在这个帖子类型中获取标签的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;
            }

1 个答案:

答案 0 :(得分: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;
}