Skip to content

Instantly share code, notes, and snippets.

@bologer
Created June 30, 2015 20:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bologer/5401a9ad7f3e60233fda to your computer and use it in GitHub Desktop.
Save bologer/5401a9ad7f3e60233fda to your computer and use it in GitHub Desktop.
Wordpress sub-categories of parent category from the current post
<?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