通过自定义帖子类型获取这些帖子的类别名称 [英] Get category name with these post by custom post type

查看:34
本文介绍了通过自定义帖子类型获取这些帖子的类别名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要按自定义帖子类型使用这些帖子名称的类别名称.
示例:

I want category name with these post name by custom post type.
Example:

Category Name: Birds
Post Name: Peacock

Category Name: Cities
Post Name: Jaipur

推荐答案

已解决.

答案是:polling-cat 是自定义帖子类型的分类名称.

The answer is: polling-cat is name of taxanomy name of custom post type.

$terms = get_terms( 'polling-cat' );
if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){
    foreach ( $terms as $term ) {
        echo $term->name;
        $args = array(
            'posts_per_page' => 5,
            'polling-cat' => $term->slug,
            'post_type' => 'polling',
            'post_status' => 'publish',
        );
        $myposts = get_posts( $args );
        foreach ( $myposts as $post ) : setup_postdata( $post );
            the_title();
        endforeach;
        wp_reset_postdata();
    }
}

这篇关于通过自定义帖子类型获取这些帖子的类别名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆