Support

Account

Home Forums General Issues Displaying a relationship field only if it exists Reply To: Displaying a relationship field only if it exists

  • I know this is an old question and the OP may not still be looking for help, but someone may have the same question.

    Using the above code to work from:

    
    global $post;
    $posts = get_field('doctors');
    if ($posts) {
        foreach ($posts as $post) {
            setup_postdata($post);
            $name = get_field('doctor_name');
            if ($name) {
                $field_object = get_field_object('doctor_name');
                echo $field_object[label],': ',$name;
            }
        } // end foreach
        wp_reset_postdata();
    } // end if posts