• Hello,
    I’m really sorry to ask again.
    I have two CPT (‘auctores’ and ‘texti’) and the first one of them is the CPT-onomy for the second one so that every single ‘texti’ post has one single ‘auctores’ as a “parent”. For example Cicero (‘auctores’) has “Cato Maior de senectute” (‘texti’) (and many others) as a child, but Cato maior de senectute has only Cicero as a parent.
    Now i’m working on the archive page for texti and I’d like to sort the list by the taxonomy ‘periodi’ which is applied to ‘auctores’.
    In the archive page for ‘auctores’ i’ve set the sorting by ‘periodi’ this way:

    <?php
            $terms = get_the_terms( $post->ID, 'periodi' );
            if ( $terms && ! is_wp_error( $terms ) ) :
                $periodi_links = array();
                foreach ( $terms as $term ) {
                    $periodi_links[] = $term->name;
                }
                $on_draught = join( ", ", $periodi_links );
            ?>
            <?php echo $on_draught; ?>
            <?php endif; ?>

    I saw this post and it seems to be quite similar to my problem, but I can’t figure how I should use wp_get_object_terms() to get the taxonomy terms.

    I’m trying from two days. I can get the parent auctor or…nothing at all.
    This is the last code i’ve tried:

    <?php
    
    global $cpt_onomy;
    $terms = wp_get_object_terms( $post->ID, 'auctores' );
    if ( $terms && !is_wp_error( $terms ) ) {
       foreach ( $terms as $term ) {
    	 {
    	   $periodi = wp_get_object_terms( $post->ID, 'periodi' );
    	   if ( $periodi && !is_wp_error( $periodi ) ) {
    		 foreach( $periodi as $term ) {
    			echo '<li><a href="' . get_term_link( $term->slug, 'periodi' ) . '"><span class="label label-default">' . esc_html( $term->name ) . '</span></a></li>';
    		 }
    	 }
       }
    }
    }
    ?>

    I’m sure it’s wrong as I’m sure I’m very bad at coding.

    I hope you would help me.
    Many thanks.

    https://wordpress.org/plugins/cpt-onomies/

  • The topic ‘Get taxonomy of the CPT-onomy of current post’ is closed to new replies.