Created
June 30, 2015 20:41
-
-
Save bologer/5401a9ad7f3e60233fda to your computer and use it in GitHub Desktop.
Wordpress sub-categories of parent category from the current post
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
# https://wordpress.org/support/topic/how-to-only-show-the-posts-child-category-inside-the-loop | |
$post_child_cat = array(); | |
foreach( (get_the_category()) as $cats) { | |
$args = array( 'child_of' => $cats->cat_ID ); | |
$categories = get_categories( $args ); | |
if( $categories ) foreach( $categories as $category ) echo '<li><a href="/cat='. $category->cat_ID.'">' . $category->cat_name . '</a></li>'; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment