Support

Account

Home Forums Front-end Issues Show field from relationship Reply To: Show field from relationship

  • The result of the relationship field is going to be an array of pages, even if only one is selected. So you would either need to loop through them or target the array index. Furthermore the result of each item in the array is an object.

    The loop would be:

    
    $companies = get_field('company');
    foreach($companies as $company){
         $company_name = $company->post_title;
         echo $company_name;
    }
    

    To target the first relationship in the array:

    
    $companiy = get_field('company');
    $company_name = $company[0]->post_title;
    echo $company_name;