Connecting Settings Page to Option Values

Support MB Settings Page Connecting Settings Page to Option Values

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #3775
    anthonycamillerianthonycamilleri
    Participant

    I have a metabox created on the settings page with a text field that supports cloning. I would like to call the values, entered on the settings page as teh Option-Values for an advanced checkbox in my plugin. Could you help me with how to do this?

    			array(
    				'name'    => __( 'Checkbox list', 'rwmb' ),
    				'id'      => "{$prefix}partners",
    				'type'    => 'checkbox_list',
    				// I would like to call value 1, value 2 etc from the values entered on the settings page.
    				'options' => array(
    					'value1' => esc_html__( 'Label1', 'your-prefix' ),
    					'value2' => esc_html__( 'Label2', 'your-prefix' ),
    #3778
    Anh TranAnh Tran
    Keymaster

    Hi, if you're using a simple cloned text field, then it has only values. In this case, I think it's best to use these values as both the value and label in the options of the check box list.

    You can use a snippet like this:

    $settings = get_option( 'option_id' );
    $values = isset( $settings['field_id'] ) ? $settings['field_id'] : array();
    $options = array();
    foreach ( $values as $value ) {
        $options[$value] = $value;
    }
    
    // In the field
    array(
        // Other options
        'options' => $options,
    )
Viewing 2 posts - 1 through 2 (of 2 total)
  • The topic ‘Connecting Settings Page to Option Values’ is closed to new replies.