List post from current taxonomy children
I have a custom post type and a taxonomy with children, with a template file named taxonomy-productcategories.php. On this i want to list all children with their posts.
Child taxonomy 1
- Child taxonomy 1 Post A
- Child taxonomy 1 Post B
- Child taxonomy 1 Post C
Child taxonomy 2
- Child taxonomy 2 Post D
- Child taxonomy 2 Post E
- Child taxonomy 2 Post F
And so on...
I have an example for getting just the Child taxonomy, but i want to add the post from each taxonomy.
?php
$term_slug = get_query_var( 'term' );
$taxonomyName = get_query_var( 'taxonomy' );
$current_term = get_term_by( 'slug', $term_slug, $taxonomyName );
$termchildren = get_term_children( $current_term-term_id, $taxonomyName );
foreach ($termchildren as $child) {
$term = get_term_by( 'id', $child, $taxonomyName );
echo "$term-name:br /";
}
?