Support

Account

Home Forums General Issues Simple ? : Displaying a relationship field

Solving

Simple ? : Displaying a relationship field

  • I must be doing something wrong as this seems like it should be pretty straightforward.

    I have 2 CPTs, ‘Books’ and ‘Authors’.

    On the Books CPT one of the ACF fields is a relationship field “authors” where you associate an author with a book – that works fine in the admin section

    On the books CPT template I have some ACF fields and are displaying wonderfully, with the exception of the relationship field. I just want to display the title of the Author CPT that is related to it.

    That’s really it.

    Thanks

  • https://www.advancedcustomfields.com/resources/relationship/

    
    $authors = get_field('author_relationship_field');
    if ($authors) {
      foreach ($authors as $post) {
        setup_post_data($post);
        the_title();
      }
      wp_reset_postdata();
    }
    
  • Thanks
    It needs to be within a post loop, displaying alongside the Books title, description, etc

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

You must be logged in to reply to this topic.