admin管理员组

文章数量:1313006

I have CPT called news and Custom Taxonomy called news_category. Below code is outputing the all category from Post. What i need is the output showing news_category from News post type, so later i can call the article from News.

class App_Default {

    public function getPosts($cat_id = '') {

    global $post, $wp_query;
    
    unset($wp_query->query['cat']);
    if (!empty($cat_id))
        $query['cat'] = $cat_id;

    $query['posts_per_page'] = 100;

    query_posts($query);

    $output = array();
    while (have_posts()) {

        the_post();

        if ($post->post_status != 'publish') continue;

        $category_ids = $this->_getCategoryIds($post->ID);

        $content = get_the_content();
        $content = apply_filters('the_content', $content);
        $content = str_replace(']]>', ']]>', $content);

        $featured_image = null;

        if( has_post_thumbnail( $post->ID ) ) {
            $featured_image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'large' );
            if(is_array($featured_image) AND !empty($featured_image[0])) {
                $featured_image = $featured_image[0];
            }
        }

        if(!empty($category_ids)) {
            $datas = array(
                'id' => $post->ID,
                'title' => $post->post_title,
                'featured_image' => $featured_image,
                'description' => $content,
                'short_description' => strip_tags(apply_filters('the_excerpt', get_the_excerpt())),
                'date' => $post->post_date,
            );

            $datas['category_ids'] = $category_ids;

            $output[$post->ID] = $datas;
        }
    }

    return $output;
}

protected function _getCategoryIds($post_id) {

    $category_ids = array();
    if ($categories = get_the_category($post_id)) {
        foreach ($categories as $category) {
              $category_ids[] = $category->term_id;
        }
    }

    return $category_ids;
}

}

本文标签: Need Output Custom Taxonomy from Custom Post Type