Support

Account

Home Forums Add-ons Repeater Field Loosing my mind. Dynamic Select Choices inside repeater.

Solving

Loosing my mind. Dynamic Select Choices inside repeater.

  • I have a repeater that contains a select field.

    Im using the load_field filter to dynamically populate the select fields’ choices on a custom post type.

    The data comes from a custom database table and are simple date values.

    The database gives me an array in the following format.

    $dates = [
    '2020-12-30'=> '30.12.2020',
    '2020-12-31'=> '31.12.2020',
    ]

    So far so good.

    Here comes the issue that is making me lose my mind.

    $field['choices'] = $dates;
    				
    return $field;

    Does result in the select field having no choices at all.

    However, returning the same array $dates hardcoded to the filter works perfectly as expected.

    $dates_manually = [
    					
    '2020-12-30'=> '30.12.2020',
    '2020-12-31'=> '31.12.2020',
    ]; 
    
    $field['choices'] = $dates_manually;
    				
    return $field;

    I tried it all. var_dump, array_diff. Everything. Its the same array. However the dynamically create $dates array results in an empty select field while the manually created one works.

    I hope anybody has an idea.

    I put the code I use in a GitHub Repo if that helps anybody.

    Thank you very much.

  • What makes this even more confusing is that the exact same code works perfectly fine for a normal select field that is not inside a repeater.

  • I have looked at your code and I don’t see any reason that this should be happening.

    Try using an acf/prepare_field filter instead of a acf/load_field and see if this makes any difference.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.