php - Wordpress - Show all child categories associated to post ID within loop -


i'm looping through posts , i'm trying output category nicename related each post. if there categories a,b , c post x associated categories , c want output category , c's nicename.

here's loop:

<?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 each post   <?php $category = get_categories($post->id);         foreach(($category) $cats) { echo $category->category_nicename; }?>  <?php endwhile; endif; ?> 

it sounds get_the_category() ideal situation, since you're doing within loop:

$post_cats = get_the_category(); if ( $post_cats ) {     foreach ( $post_cats $cat ) {         // show child categories (exclude parents)         if ( ! $cat->category_parent === '0' ) {             echo $cat->cat_name;         }     } } 

Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -