0

This is the custom post type structure I have:

Custom Post Type

  • Custom Taxonomy

    • Sub Taxonomy 1

    • Sub Taxonomy 2

    • Sub Taxonomy 3

On the current Custom Post Type post/page, I need the code that finds the Sub Taxonomy (or Sub Taxonomies) of that post and output it as a link to other posts with the same sub taxonomy (separated by a comma, if it has more than one Sub Taxonomy).

The following code is close to what I'm looking for but I need it for the current post, I don't want it as a list and there has to be a comma separating them if there's more than one

<?php
$term_id = 10;
$taxonomy_name = 'products';
$termchildren = get_term_children( $term_id, $taxonomy_name );

echo '<ul>';
foreach ( $termchildren as $child ) {
    $term = get_term_by( 'id', $child, $taxonomy_name );
    echo '<li><a href="' . get_term_link( $term->name, $taxonomy_name ) . '">' . $term->name . '</a></li>';
}
echo '</ul>';
?> 
  • this answer may help you out. – Milo Oct 24 '13 at 15:37
  • Is this resolved and can be marked as duplicate of said thread then? :) – Rarst Oct 24 '13 at 19:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.