【问题标题】:How do you get the tag id of post type你如何获得帖子类型的标签ID
【发布时间】:2014-03-04 11:32:06
【问题描述】:

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

【问题讨论】:

    标签: php arrays wordpress


    【解决方案1】:

    你可以使用下面的函数来获取term 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;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-20
      • 2017-12-14
      • 1970-01-01
      • 2021-09-11
      • 2023-04-03
      相关资源
      最近更新 更多