Advanced Custom Fields how can I register Select options programmatically

264 Views Asked by At

I can register a Year field programmatically for ACF with code like the following that has a 33% width of the container:

if( function_exists('acf_add_local_field_group') ):

acf_add_local_field_group(array (
    'key' => 'group_1',
    'title' => 'My Group',
    'fields' => array (
        array (
            'key' => 'year',
            'label' => 'Year',
            'name' => 'year',
            'type' => 'select',
            'prefix' => '',
            'instructions' => '',
            'required' => 1,
            'conditional_logic' => 0,
            'wrapper' => array (
                'width' => '33%',
                'class' => 'year',
                'id' => '',
            ),
            'default_value' => '',
            'placeholder' => '',
            'prepend' => '',
            'append' => '',
            'maxlength' => '',
            'readonly' => 0,
            'disabled' => 0,
        )
    ),
    'location' => array (
        array (
            array (
                'param' => 'post_type',
                'operator' => '==',
                'value' => 'post',
            ),
        ),
    ),
    'menu_order' => 0,
    'position' => 'normal',
    'style' => 'default',
    'label_placement' => 'top',
    'instruction_placement' => 'label',
    'hide_on_screen' => '',
));

endif;

How do I add year options to the select e.g. 2023, 2024, 2025 etc?

How do I add extra fields to this field group such as Week and Term, where Week has 12 options and Term has 4 options?

0

There are 0 best solutions below