JoeSz / Exopite-Simple-Options-Framework

Fast, easy and lightweight admin options/metabox form generator for WordPress Plugins and metaboxes.
GNU General Public License v3.0
78 stars 24 forks source link

get repeater values [question] #27

Closed luis9430 closed 4 years ago

luis9430 commented 4 years ago

Hello! I'm trying to get the values ​​in the repeater, but I don't know very well how, this is my code

` $config_submenu = array(

        'type'              => 'menu',                          // Required, menu or metabox
        'id'                => $this->plugin_name,              // Required, meta box id, unique per page, to save: get_option( id )
        'parent'            => 'plugins.php',                   // Required, sub page to your options page
        'submenu'           => true,                            // Required for submenu
        'title'             => 'Exopite Combiner Minifier',     // The name of this page
        'capability'        => 'manage_options',                // The capability needed to view the page
        'plugin_basename'   =>  plugin_basename( plugin_dir_path( __DIR__ ) . $this->plugin_name . '.php' ),
        // 'tabbed'            => false,
        'multilang'         => false,

    );

    $fields[] = array(
        'title'  => 'General',
        'icon'   => 'dashicons-admin-settings',
        'name'   => $this->plugin_name,
        'fields' => array(
            array(
                'type'    => 'group',
                'id'      => 'group_1_sortable',
                'title'   => esc_html__( 'Sortable, repetable field multiple', 'plugin-name' ),
                'options' => array(
                    'repeater'          => true,
                    'accordion'         => true,
                    'button_title'      => esc_html__( 'Add new', 'plugin-name' ),
                    'group_title'       => esc_html__( 'Accordion Title', 'plugin-name' ),
                    'limit'             => 50,
                    'sortable'          => true,
                    'mode'              => 'compact',
                ),
                'fields'  => array(

                    array(
                        'id'      => 'group_1_sortable_text_1',
                        'type'    => 'text',
                        'attributes' => array(
                            // mark this field az title, on type this will change group item title
                            'data-title' => 'title',
                            'placeholder' => esc_html__( 'Some text', 'plugin-name' ),
                        ),
                    ),

                    array(
                        'id'      => 'group_1_sortable_text_2',
                        'type'    => 'text',
                        'attributes' => array(
                            // mark this field az title, on type this will change group item title
                            'data-title' => 'title',
                            'placeholder' => esc_html__( 'Some text', 'plugin-name' ),
                        ),
                    ),

                ),
            ),

        ),
    );

`

the values ​​i have are these

values

i try to do this function and it returns "A" "C" but I don't know how to make it return the values ​​separately,

` function carousel(){

$my_options = get_option( 'exopite-combiner-minifier' );

$slider = $my_options['group_1_sortable'];

  foreach($slider as $key =>  $value){ 

        echo $value['group_1_sortable_text_1'];

  }

`

I hope you can help me, thanks in advance!

JoeSz commented 4 years ago

Hi, here you can see some examples. https://github.com/JoeSz/Exopite-Simple-Options-Framework/blob/e7e9606c84498914fa939da9e1ff8decb5a63b46/exopite-simple-options/exopite-simple-options-framework-class.php#L1948

You are in a wrong track. get_options need your plugin name, then you can dump all options, like this:

$my_options = get_option( $this->plugin_name );
echo '<pre>' . var_export( $my_options, true ) . '</pre>';

This is also in your code above:

'id'                => $this->plugin_name,              // Required, meta box id, unique per page, to save: get_option( id )

'id' => 'group_1_sortable', <- this will be an array

luis9430 commented 4 years ago

Thanks for answering, just one more question, to make the typography work in a repeater text, how could I do it?

JoeSz commented 4 years ago

I suggest to take a look in: https://github.com/JoeSz/WordPress-Plugin-Boilerplate-Tutorial

Install the example plugin and there you can see, how you can do that. (and more, basically all fields and usage is there) eg.: https://github.com/JoeSz/WordPress-Plugin-Boilerplate-Tutorial/blob/5a9b0fe3010f90f7aaefa3db3d0c52dd1982b41e/plugin-name/admin/class-plugin-name-admin.php#L1066

luis9430 commented 4 years ago

thanks for your help! I will install the example plugin