Support

Account

Home Forums General Issues Pre-populating content with configuration file

Solved

Pre-populating content with configuration file

  • Greetings,

    I am trying to develop a select field which pre-populates with results from another field. I am generating sidebars with repeaters, and want to be able to select these sidebars on actual pages, so the sidebar slugs need to pre-populate the page fields.

    I am using a configuration file, which I fear may be the issue as you can see below the configuration file is pre-populating with my development garage.

    ‘id’ => ‘acf_select-sidebar’,
    ‘title’ => ‘Select Sidebar’,
    ‘fields’ => array (
    array (
    ‘key’ => ‘field_53d63fafa2145’,
    ‘label’ => ‘Select Sidebar’,
    ‘name’ => ‘select_sidebar’,
    ‘type’ => ‘select’,
    ‘choices’ => array (
    ‘karma’ => ‘Karma’,
    ‘asdf’ => ‘asdf’,
    ),
    ‘default_value’ => ”,
    ‘allow_null’ => 1,
    ‘multiple’ => 0,
    ),
    ),

    Here’s the filter which I wish worked.

    function act_load_sidebar_default( $field ) {

    $field[‘choices’] = array();

    // Get field from options page

    if ( get_field( ‘sidebar_actual’, ‘option’, false ) ):

    $row_count = 0;

    while ( have_rows( ‘sidebar_actual’, ‘option’ ) ): the_row();

    $label = get_sub_field(‘sidebar_title’);
    $value = get_sub_field(‘sidebar_slug’);
    //
    $field[‘choices’][$value] = $label;

    endwhile;

    endif;

    return $field;

    }

    add_filter(‘acf/load_field/name=field_53d63fe4f2ad9’, ‘act_load_sidebar_default’);

    Any help would be greatly appreciated.

  • I should mention — I noticed I’m actually using this functionality 4 separate times, and it’s working with two. The two that is does work, the only difference is that the sidebar slugs are not draw from nested repeaters, but only single level repeaters..

  • During development the fields were replaced, and the field name wasn’t consistent with the configuration file. The local version worked because the post table had old field still in place. Sorry for wasting you time!

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

The topic ‘Pre-populating content with configuration file’ is closed to new replies.