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


Dynamically select field don't update

    • Trint33

    • November 29, 2020 at 9:32 pm

    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.


    • Trint33

    • December 1, 2020 at 7:25 pm

    nobody can help me on this ?


    • Trint33

    • December 3, 2020 at 4:21 am

    I’m trying to use this :

    Is it the key to success ?

    • Trint33

    • December 3, 2020 at 6:52 am

    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.

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.