Support

Account

Home Forums Backend Issues (wp-admin) Display field from another CPT Reply To: Display field from another CPT

  • You need to do a reverse relationship query in CPT2 to get the post for CPT1

    
    $args = array(
      'post_type' => 'CPT#2',
      'posts_per_page' => '1', // assuming there is only one
      'meta_query' => array(
        array(
          'key' => 'RELATIONSHIP_FIELD_NAME',
          'value' => '"'.$post->ID.'"',
          'compare' => 'LIKE'
        )
      )
    );
    $query = new WP_Query($args);
    if ($query->have_posts) {
      $related_id = $query->posts[0]->ID;
      // get field from the other post
      $value = get_field('some other field', $related_id);
    }
    

    see this page for more on reverse relationship queries https://www.advancedcustomfields.com/resources/querying-relationship-fields/