Home Forums Backend Issues (wp-admin) Dynamically select field don't update


Dynamically select field don't update

  • Hello everybody,
    I followed this tutorial so as to create a color field in theme options that feed my all pages with a select field (none, color 1, color 2,…)
    I works great, field is displayed and I can change color on my page according to the selected value.
    However I have an issue, when I update color in theme options, it resets my color field with the first choice which is none and I must update the selected field on pages each time I update a color.
    It loses all its usefulness…
    Here is my function :

    function acf_load_color_field_choices( $option_color ) {
        // reset choices
        $option_color['choices'] = array();
        // if has rows
        if( have_rows('couleurs', 'option') ) {
            // while has rows
            while( have_rows('couleurs', 'option') ) {
                // instantiate row
                // vars
                $label = get_sub_field('nom_couleur');
                $value = get_sub_field('couleur');
                // append to choices
                $option_color['choices'][ $value ] = $label;
                //$option_color['default_value'] = 'Aucune couleur';
        // return the field
        return $option_color;
    add_filter('acf/load_field/name=menu_color', 'acf_load_color_field_choices');

    Any help appreciated ;-).

    All the best.


  • Hello,
    nobody can help me on this ?


  • Sometimes you have to take a step back…
    name=menu_color wasn’t the right ACF field…

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

You must be logged in to reply to this topic.