0

I have a custom post type, called prognosis with 3 custom taxonomies, Country, Competition, and Sport, I've also added a few ACF custom fields. I have another custom post type called analysis with an ACF relationship field prognosis connected to the prognosis custom post type.

I want to be able to display certain taxonomy/ies the custom post type prognosis is connected to, through the relationship field that I have selected in the analysis custom post type. I tried debugging the prognosis relationship field but I don't see any taxonomies attached to it.

1 Answer 1

0

I managed to solve my issue by looping through a get_the_terms() function. In my case, I've also created a shortcode.

function display_taxonomy() { 

$prognoses = get_field('prognosis');
ob_start();
if( $prognoses ):
foreach( $prognoses as $prognosis ):
    $terms = get_the_terms( $prognosis->ID , 'my_custom_taxonomy' );
    foreach ( $terms as $term ):
        echo $term->name;
    endforeach;
endforeach;
endif;
return ob_get_clean();
}

add_shortcode( 'my_custom_taxonomy_shortcode', 'display_taxonomy' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.