Support

Account

Home Forums ACF PRO Display ACF field's Taxonomy in Custom Post Type

Solved

Display ACF field's Taxonomy in Custom Post Type

  • Hi there,
    I would like to display an ACF link from Custom Taxonomy to Custom Post Type’archive. In fact I want to replace the taxonomy’s link with another ACF link, only for CPT.

    This is my situation:
    1- I have the ACF link inside Custom Taxonomy.
    2- I have the archive with loop of CPT.
    3- This is the loop, where $term_link should be replaced with ACF link.

    <?php if ( have_posts() ) : ?>
    <?php while ( have_posts() ) : the_post(); ?>
    
    <div <?php post_class(); ?> id="post-<?php the_ID(); ?>">
    
    <?php $terms = get_the_terms( $post->ID , 'name_taxonomy' );
    foreach ( $terms as $term ) {
    
    $term_link = get_term_link( $term, 'name_taxonomy' );
    if( is_wp_error( $term_link ) )
    continue;
    echo '<a href="' . $term_link . '">' . $term->name . '</a>';
    }
    
    ?>
    
    </div>
    
    <?php endwhile; ?>
    <?php wp_reset_postdata(); ?>
    <?php endif; ?>

    Any suggests? Thank you so much!

  • 
    $term_link = get_field('link-field-name', $term);
    
Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Display ACF field's Taxonomy in Custom Post Type’ is closed to new replies.