我正在遍历所有帖子,并试图输出与每个帖子相关的类别nicename。因此,如果有类别A、B和C,并且帖子X只与类别A和C关联,那么我只想输出类别A和C的nicename。
以下是循环:
<?php $subs = new WP_Query( array( \'post_type\' => \'case-study\' ));
if( $subs->have_posts() ) : while( $subs->have_posts() ) : $subs->the_post(); ?>
<?php the_title(); ?>
<p>Associated Child Categories</p>
//Show nicenames of each child category associated to each post
<?php $category = get_categories($post->ID);
foreach(($category) as $cats) { echo $category->category_nicename; }?>
<?php endwhile; endif; ?>