Home › Forums › General Issues › Relationship field returning ID, how to return the correct values. › Reply To: Relationship field returning ID, how to return the correct values.
I managed to get the correct wording to display in the drop down. Does this look like best practice for retrieving that info. But its now throwing errors in the wp-admin from this line = $studio_id = $GLOBALS[‘post’]->ID;
add_filter( 'gform_pre_render', 'freetrial_studios' );
add_filter( 'gform_pre_validation', 'freetrial_studios' );
add_filter( 'gform_pre_submission_filter', 'freetrial_studios' );
add_filter( 'gform_admin_pre_render', 'freetrial_studios' );
function freetrial_studios( $form ) {
foreach ( $form['fields'] as &$field ) {
if ( $field->type != 'select' || strpos( $field->cssClass, 'studio-list' ) === false ) {
continue;
}
$studio_id = $GLOBALS['post']->ID;
$studios = get_field('field_557a974776dd2', $studio_id);
if( $studios ) {
$choices = array();
foreach ( $studios as $studio ) {
// Populate the drop down field with values
$choices[] = array( 'text' => $studio->post_title, 'value' => $studio->post_title );
$field->choices = $choices;
}
$field->placeholder = 'Select a Studio';
$field->choices = $choices;
}
}
return $form;
}
Also Any idea on how i could get the value of that selected field, and retrieve a custom field that is related to that post ID eg. a custom email address field that i have set up for each studio.
Thanks
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
π Weβre excited to announce we've released Composer support for installing ACF PRO.
— Advanced Custom Fields (@wp_acf) January 31, 2023
π #ComposerPHP fans rejoice!
β¨ Please see the release post for all the details and full instructions. https://t.co/ebEfp61nlR
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.