wordpress redux framework – create a repeater field and show values later

I am trying to use Redux inside the wordpress theme and not as a plugin. In functions.php I included both redux-framework.php and sample-config.php .

Now I need to create a repeater field.

From Redux doc, I got the following code to use in order to create a repeater field:

$this->sections[] = array(
    'title' => __('Repeater Field', 'redux-framework-demo' ),
    'icon' => 'el-icon-thumbs-up',
    'fields' => array(
        array(
            'id'         => 'repeater-field-id',
            'type'       => 'repeater',
            'title'      => __( 'Title', 'redux-framework-demo' ),
            'subtitle'   => __( '', 'redux-framework-demo' ),
            'desc'       => __( '', 'redux-framework-demo' ),
            //'group_values' => true, // Group all fields below within the repeater ID
            //'item_name' => '', // Add a repeater block name to the Add and Delete buttons
            //'bind_title' => '', // Bind the repeater block title to this field ID
            //'static'     => 2, // Set the number of repeater blocks to be output
            //'limit' => 2, // Limit the number of repeater blocks a user can create
            //'sortable' => false, // Allow the users to sort the repeater blocks or not
            'fields'     => array(
                array(
                    'id'          => 'title_field',
                    'type'        => 'text',
                    'placeholder' => __( 'Title', 'redux-framework-demo' ),
                ),
                array(
                    'id'          => 'text_field',
                    'type'        => 'text',
                    'placeholder' => __( 'Text Field', 'redux-framework-demo' ),
                ),
                array(
                    'id'          => 'select_field',
                    'type'        => 'select',
                    'title' => __( 'Select Field', 'redux-framework-demo' ),
                    'options'     => array(
                        '1'             => __( 'Option 1', 'redux-framework-demo' ),
                        '2'             => __( 'Option 2', 'redux-framework-demo' ),
                        '3'             => __( 'Option 3', 'redux-framework-demo' ),
                    ),
                    'placeholder' => __( 'Listing Field', 'redux-framework-demo' ),
                ),
            )
        )
    )
);

but if I place the code inside functions.php, what will the $this variable refer to? It’ll produce errors. So how to use the snippet so that I can retrieve the values from template files as well?

Read more here: wordpress redux framework – create a repeater field and show values later

Leave a Reply

Your email address will not be published. Required fields are marked *