1
votes

I'm using the following code to get a list of post titles which were set with ACF Relationship. Question is how to get custom field values on the other post type. (I only can get post meta info at the moment)

<form id="course-drop" name="course-drop" class="wpcf7-form" method="get" action="">
<select name="provider" id="provider" class="form-control">
    <option value="">---</option>
    <?php
        $course_providers = get_posts(array(
            'post_type' => 'course_providers',
            'meta_query' => array(
                array(
                'key' => 'courses_offered',
                'value' => '"' . get_the_ID() . '"',
                'compare' => 'LIKE'
                )
            )
        ));
    ?>

    <?php if( $course_providers ): ?>
        <?php foreach( $course_providers as $course_provider ): ?>
            <option value="<?php echo get_the_title( $course_provider->ID ); ?>" data-email="<?php echo the_field('email_address'); ?>"><?php echo get_the_title( $course_provider->ID ); ?></option>
        <?php endforeach; ?>
    <?php endif; ?>

</select>

check the data attribute I have tried which I need to get the email.

Ref used: https://www.advancedcustomfields.com/resources/querying-relationship-fields/

1

1 Answers

0
votes

You can use the following to get the custom field of a post.

<?php echo the_field('email_address', 123); ?>  //replace your post id with 123