Support

Account

Home Forums ACF PRO Can't retrieve repeater values from options page Reply To: Can't retrieve repeater values from options page

  • I was curious, so I created an options page using the following

    
    $args = array(
      'title' => 'MY_OPTIONS_PAGE',
      'menu_title' => 'MY_OPTIONS_PAGE',
      'menu_title' => 'MY_OPTIONS_PAGE',
      'post_id' => 'MY_OPTIONS_PAGE'
    );
    

    Then I create a test field group with just a text field named “where_am_i”. I saved a value to it and then search the db for the value I save. It turned up in the options table with an option name of MY_OPTIONS_PAGE_where_am_i. I also tried some other field examples including a repeater field and they all end up in the options table with the prefix of MY_OPTIONS_PAGE_ and everything worked as expected, although I’m not exactly sure how because for me this is unexpected behavior (but intriguing since this opens up things I was not aware of)

    Anyway, this leads to the question of, if it does work, why isn’t it working for you.

    The only answer that I can come up with here is that you have another field that also evaluates to the option name of MY_OPTIONS_PAGE_MY_REPEATER... or that somehow your filter is interfering with the working of your have_rows() loop, though I can’t say why. When I run the code for the options in my page template on the site everything is working.

    For your last example try something like

    
    <?php
    function set_acf_rgba_color_picker_palette() {
        // optional - add colors which are not set in the options page
        $palette = array(
            '#FFF',
            '#000'
        );
    
        // ====================================================================
        // Try to the repeater as an array
        // ====================================================================
        $test = get_field('MY_REPEATER', 'MY_OPTIONS_PAGE');
        echo "<pre>";
        print_r($test);
        echo "</pre>";
    
        if ( have_rows('MY_REPEATER', 'MY_OPTIONS_PAGE') ) {
            while( have_rows('MY_REPEATER', 'MY_OPTIONS_PAGE') ) { the_row();
                $palette[] = get_sub_field('MY_COLOR_FIELD');
            }
        }
    
        return $palette;
    }
    add_filter('acf/rgba_color_picker/palette', 'set_acf_rgba_color_picker_palette');
    ?>