Hi,
I am trying to populate a select field with a text field from a repeater but it is giving me a 500 error that is difficult to debug.
The repeater is part of the same custom post. Not too much documentation on how to go about this.
thanks,
Paul
add_filter('acf/load_field/name=no_complete_target', 'acf_load_complete_field_choices');
function acf_load_complete_field_choices($field){
$post_id = get_the_ID();
if ( have_rows( 'group', $post_id ) ):
while ( have_rows( 'group', $post_id ) ) : the_row();
if ( have_rows( 'result', $post_id ) ):
while ( have_rows( 'result', $post_id ) ) : the_row();
$title = get_sub_field( 'result_title', $post_id );
// once this works this will be
// $field['choices'] = $title;
echo $title . '';
endwhile;
endif;
endwhile;
endif;
return $field;
}
Hi,
I figured out that this is not possible.
Repeater
– Repeater
-Text Field
– Repeater
Hi,
I figured out that this is not possible.
Repeater
– Repeater
– – Text Field
– Repeater
– – Select Field Loaded from Text Field Above
The error was Trying to get property of non-object
So I rethought the data and realized I dould get rid of one of the parent repeater went with this
– Repeater
– – Text Field (result_title)
– Repeater
– – Select Field Loaded from Text Field Above (yes_complete_target)
The code then is
add_filter('acf/load_field/name=yes_complete_target', 'acf_load_complete_field_choices');
function acf_load_complete_field_choices($field){
global $post;
$post_id = $post->ID;
$field['choices'] = array();
//Get the repeater field values
$choices = get_field( 'dt_result', $post_id );
$keys = array_keys($choices);
for($i = 0; $i < count($choices); $i++) {
foreach($choices[$keys[$i]] as $key => $value) {
if($key == 'result_title'){
$title = $value;
//echo $value . "<br>";
$field['choices'][$title] = $title;
}
}
}
return $field;
}
You must be logged in to reply to this topic.
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!
Are you building WordPress sites with ACF and @BeaverBuilder, and wanted to use your ACF Blocks in both the block editor and Beaver Builder?
— Advanced Custom Fields (@wp_acf) May 10, 2023
The BB team recently added support for using ACF Blocks in Beaver Builder. Check it out 👇https://t.co/UalEIa5aQi
© 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.