Hello I have followed this link -> http://www.advancedcustomfields.com/resources/tutorials/dynamically-populate-a-select-fields-choices/
Yet I can not create options for a select field. I am putting this code in the functions.php
function my_acf_load_field( $field )
{
$field['choices'] = array();
$choices = get_field('text_fielder', 'option', false);
$choices = explode("\n", $choices);
$choices = array_map('trim', $choices);
if( is_array($choices) )
{
foreach( $choices as $choice )
{
$field['choices'][ $choice ] = $choice;
}
}
return $field;
}
add_filter('acf/load_field/name=select_fielder', 'my_acf_load_field');
I have tried putting field_keys instead of names yet still the select options are all empty… WP debug is not returning any errors also…
I have also tried these
$choices = get_field('text_fielder');
// Or
$choices = get_field('text_fielder', 'options', false);
Yet no luck 🙁
Any ideas… Thanks…
Hi @downer
Can you please confirm that your filter is working correctly by adding this debug code to the start of the function:
echo '<pre>';
print_r('test');
echo '</pre>';
die;
When you edit a post which contains this field, do you see the ‘test’ text on the screen?
Thanks
E
Yes, I can see “test” on the screen…
Hi @downer
Your next step is to move through your filter code line by line and move the print_r statement through it and display the variable from the line above. This is called ‘debugging’ and will help you find the line of code which is not working.
Thanks
E