Home Forums ACF PRO Relationship : CPT taxonomy and regular post


Relationship : CPT taxonomy and regular post

  • Hello,

    I try to display the taxonomy(ies) “auteur” and its link from a CPT called “membre” to regular posts. I read the documention about relationship but there’s nothing about this. the relationship field is called “article-membre”.

    My code is the following (in the loop of index.php) :

    <?php $auteurs = get_field('article-membre');	?>
    <?php if( $auteur ): ?>
    <?php foreach( $auteurs as $auteur ): ?>
    <?php setup_postdata($auteur); ?>
    <a href="<?php echo get_permalink( $auteur->ID ); ?>"><?php echo get_the_title( $auteur->ID ); ?></a>
    <?php echo get_field( 'auteur', $auteur->ID ); // name of the taxonomy but it can't display the terms ?>
    <?php endforeach; ?>
    <?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
    <?php endif; ?>

    Could you help me please ?

    Best regards.

  • What is the field type and settings for the field you’re trying to get on this line?

    <?php echo get_field( 'auteur', $auteur->ID ); // name of the taxonomy but it can't display the terms ?>
  • Hello John,

    In fact, “auteur” is a Custom taxonomy for the CPT “membres”. It’s not a field…

  • But you’re using get_field to get the values, so I’m assuming that you have an ACF taxonomy field set up for it. Is that correct or not?

  • No, haven’t this field.
    But if i create this field, i have twice checkboxes in CPT “membres” : this one of the Custom taxonomy and this one of the taxonomy field

  • Then, is it possible to do without the taxonomy field and only use the custom taxonomy ?

  • If you use a taxonomy field then you can look at this documentation on how to display the information from the taxonomy

    If you don’t use a taxonomy field and use the standard WP taxonomy box then you’ll need to look at this

  • Ok, it works with :

    <?php $terms = get_the_terms( $auteur->ID, 'auteur' ); 
    foreach($terms as $term) {
    $term_link = get_term_link( $term );
    echo '<a href="' . esc_url( $term_link ) . '">' . $term->name . '</a>';
    } ?>

    Thank you John

Viewing 8 posts - 1 through 8 (of 8 total)

The topic ‘Relationship : CPT taxonomy and regular post’ is closed to new replies.