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
版权声明:本文标题:Need Output Custom Taxonomy from Custom Post Type 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741826535a2399674.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论