我想通过自定义帖子类型使用这些帖子名称的类别名称。
例如:
Category Name: Birds
Post Name: Peacock
Category Name: Cities
Post Name: Jaipur
答案 0 :(得分:0)
解决。
答案是: polling-cat是自定义帖子类型的分类名称。
$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();
}
}