SHOW:
|
|
- or go back to the newest paste.
1 | - | add_settings_field( |
1 | + | $this->options = get_option( 'test' ); |
2 | ||
3 | add_settings_field( | |
4 | 'category_options_select', | |
5 | 'Category', | |
6 | array( $this, 'category_options_select_callback' ), | |
7 | 'my-setting-admin', | |
8 | 'api_options', | |
9 | array ( | |
10 | 'label_for' => 'Categories', // makes the field name clickable, | |
11 | 'name' => 'category', // value for 'name' attribute | |
12 | 'options' => array ( | |
13 | '1' => '1', | |
14 | '2' => '2', | |
15 | '3' => '3', | |
16 | ), | |
17 | 'option_name' => 'test' | |
18 | ) | |
19 | ); | |
20 | ||
21 | function category_options_select_callback( $args ) | |
22 | { | |
23 | printf( | |
24 | '<select name="%1$s[%2$s]" id="%3$s">', | |
25 | $args['option_name'], | |
26 | $args['name'], | |
27 | $args['label_for'] | |
28 | ); | |
29 | ||
30 | foreach ( $args['options'] as $val => $title ) | |
31 | printf( | |
32 | - | selected( $val, $this->options['categories'], FALSE ), |
32 | + | |
33 | $val, | |
34 | selected( $val, $this->options['category_options_select'], FALSE ), | |
35 | $title | |
36 | ); | |
37 | ||
38 | print '</select>'; | |
39 | } |