Select
Creates a select field with dropdown options.

Code

Field
Features
Example 1
Example 2
Example 3
1
$this_field = $this_field_instance->select('my_field_id');
Copied!
1
// CREATE: $this_field to our desired field type via our $this_field_instance variable
2
$this_field = $this_field_instance->this_field('my_field_id');
3
4
// ASSIGN: our global field features
5
// NOTE: these features are available to all field types but are considered unique,
6
// like layout, style, dependency values and validation methods, etc...
7
$this_field->horizontal(true); // DEFAULT: false
8
$this_field->style('width: 100%;'); // DEFAULT: false
9
10
// ASSIGN: our unique field features
11
// NOTE: these features are only available to this field type
12
// CONTROLS: this_feature_method | DEFAULT: value
13
$this_field->this_feature_method();
Copied!
Function Method
1
// CALL: wponion/loaded action to load our my_function function
2
add_action('wponion/loaded', 'my_function');
3
4
// CREATE: my_function to load our field and module routine
5
function my_function() {
6
7
// CREATE: our wponion_builder variable instance
8
// NOTE: we always create a wponion_builder variable instance to boot any wponion feature,
9
// then we determine what to do with that instance and its stored arguments
10
$this_field_instance = wponion_builder();
11
12
// CREATE: $this_field to our desired field type via our $this_field_instance variable
13
$this_field = $this_field_instance->select('my_field_id');
14
15
// ASSIGN: our general field features
16
// NOTE: these features are available to ALL field types but are considered general,
17
// like title, text descriptions, debug, etc...
18
$this_field->title(__('My Field Label')); // DEFAULT: false
19
$this_field->desc(__('My field description...')); // DEFAULT: false
20
$this_field->desc_field(__('My field description...')); // DEFAULT: false
21
// $this_field->debug(true); // DEFAULT: false
22
23
// ASSIGN: our unique field features
24
// NOTE: these features are ONLY available to this field type
25
// CONTROLS: this_feature_method | DEFAULT: value
26
// $this_field->this_feature_method();
27
28
// ASSIGN: our global field features
29
// NOTE: these features are available to ALL field types but are considered unique in their usage,
30
// like layout, custom css, dependency values and validation methods, etc...
31
$this_field->horizontal(true); // DEFAULT: false
32
$this_field->style('width: 100%;'); // DEFAULT: false
33
$this_field->help(array('content' => __('My field tooltip...'))); // DEFAULT: false
34
35
// ASSIGN: option values and their names to our select field dropdown
36
// MANUAL: ungrouped options
37
// $this_field-options(array(
38
// 'my_field_value_1_1' => __('My Field Label 1'),
39
// 'my_field_value_1_2' => __('My Field Label 2'),
40
// 'my_field_value_1_3' => __('My Field Label 3'),
41
// ));
42
// MANUAL: grouped options
43
$this_field->options(array(
44
__('My Field Group Label 1') => array(
45
'my_field_value_1_1' => __('My Field Label 1'),
46
'my_field_value_1_2' => __('My Field Label 2'),
47
'my_field_value_1_3' => __('My Field Label 3'),
48
),
49
__('My Field Group Label 2') => array(
50
'my_field_value_2_1' => __('My Field Label 1'),
51
'my_field_value_2_2' => __('My Field Label 2'),
52
'my_field_value_2_3' => __('My Field Label 3'),
53
),
54
));
55
// PREDEFINED: list
56
// $this_field->options('pages'); // VALUES: pages, posts, categories, tags
57
// CUSTOM: post type list
58
// NOTE: must use with $this_field->options('posts');
59
// $this_field->options('posts');
60
// $this_field->query_args(array('post_type' => 'product'));
61
// CUSTOM: taxonomy list
62
// NOTE: must use with $this_field->options('category or tags');
63
// $this_field->options('category');
64
// $this_field->query_args(array(
65
// 'option_key' => 'slug',
66
// 'option_value' => 'term_name',
67
// 'option_label' => '#[term_id] | [name] | ([count])'
68
// ));
69
70
// CREATE: $this_module_instance options array
71
// NOTE: these options vary depending on the module output you choose
72
// like wponion_admin_page, wponion_metabox, wponion_taxonomy, etc...
73
$this_module_instance = array(
74
'metabox_title' => __('My Metabox Title'),
75
'metabox_id' => 'my-metabox-id',
76
'option_name' => 'my_metabox_name',
77
'screens' => array('post', 'page', 'product',),
78
'context' => 'normal',
79
'theme' => 'wp',
80
'ajax' => true,
81
);
82
83
// CALL: our wponion_metabox module
84
// NOTE: Here you can call your desired module method
85
// like wponion_admin_page, wponion_metabox, wponion_taxonomy, etc...
86
// We are passing our module settings and our various field settings into our desired module output
87
// NOTE: in a more real world use, $this_field_instance would contain multiple fields and their settings
88
// instead of the one field shown in our documentation demo
89
wponion_metabox($this_module_instance, $this_field_instance);
90
91
}
Copied!
Class Method
1
// IF: My_Class does not exist
2
if (!class_exists('My_Class')) {
3
4
// CALL: wponion/loaded action to load our My_Class class
5
add_action('wponion/loaded', function() {
6
7
// INSTANTIATE: My_Class
8
new My_Class();
9
10
});
11
12
// CREATE: My_Class class
13
final class My_Class {
14
15
// CREATE: our class constructor method
16
public function __construct() {
17
18
// CALL: my_function to load our field and module routine
19
$this->my_function();
20
21
}
22
23
// CREATE: my_function function to load our field and module routine
24
private function my_function() {
25
26
// CREATE: our wponion_builder variable instance
27
// NOTE: we always create a wponion_builder variable instance to boot any wponion feature,
28
// then we determine what to do with that instance and its stored arguments
29
$this_field_instance = wponion_builder();
30
31
// CREATE: $this_field to our desired field type via our $this_field_instance variable
32
$this_field = $this_field_instance->select('my_field_id');
33
34
// ASSIGN: our general field features
35
// NOTE: these features are available to ALL field types but are considered general,
36
// like title, text descriptions, debug, etc...
37
$this_field->title(__('My Field Label')); // DEFAULT: false
38
$this_field->desc(__('My field description...')); // DEFAULT: false
39
$this_field->desc_field(__('My field description...')); // DEFAULT: false
40
// $this_field->debug(true); // DEFAULT: false
41
42
// ASSIGN: our unique field features
43
// NOTE: these features are ONLY available to this field type
44
// CONTROLS: this_feature_method | DEFAULT: value
45
// $this_field->this_feature_method();
46
47
// ASSIGN: our global field features
48
// NOTE: these features are available to ALL field types but are considered unique in their usage,
49
// like layout, custom css, dependency values and validation methods, etc...
50
$this_field->horizontal(true); // DEFAULT: false
51
$this_field->style('width: 100%;'); // DEFAULT: false
52
$this_field->help(array('content' => __('My field tooltip...'))); // DEFAULT: false
53
54
// ASSIGN: option values and their names to our select field dropdown
55
// MANUAL: ungrouped options
56
// $this_field-options(array(
57
// 'my_field_value_1_1' => __('My Field Label 1'),
58
// 'my_field_value_1_2' => __('My Field Label 2'),
59
// 'my_field_value_1_3' => __('My Field Label 3'),
60
// ));
61
// MANUAL: grouped options
62
$this_field->options(array(
63
__('My Field Group Label 1') => array(
64
'my_field_value_1_1' => __('My Field Label 1'),
65
'my_field_value_1_2' => __('My Field Label 2'),
66
'my_field_value_1_3' => __('My Field Label 3'),
67
),
68
__('My Field Group Label 2') => array(
69
'my_field_value_2_1' => __('My Field Label 1'),
70
'my_field_value_2_2' => __('My Field Label 2'),
71
'my_field_value_2_3' => __('My Field Label 3'),
72
),
73
));
74
// PREDEFINED: list
75
// $this_field->options('pages'); // VALUES: pages, posts, categories, tags
76
// CUSTOM: post type list
77
// NOTE: must use with $this_field->options('posts');
78
// $this_field->options('posts');
79
// $this_field->query_args(array('post_type' => 'product'));
80
// CUSTOM: taxonomy list
81
// NOTE: must use with $this_field->options('category or tags');
82
// $this_field->options('category');
83
// $this_field->query_args(array(
84
// 'option_key' => 'slug',
85
// 'option_value' => 'term_name',
86
// 'option_label' => '#[term_id] | [name] | ([count])'
87
// ));
88
89
// CREATE: $this_module_instance options array
90
// NOTE: these options vary depending on the module output you choose
91
// like wponion_admin_page, wponion_metabox, wponion_taxonomy, etc...
92
$this_module_instance = array(
93
'metabox_title' => __('My Metabox Title'),
94
'metabox_id' => 'my-metabox-id',
95
'option_name' => 'my_metabox_name',
96
'screens' => array('post', 'page', 'product',),
97
'context' => 'normal',
98
'theme' => 'wp',
99
'ajax' => true,
100
);
101
102
// CALL: our wponion_metabox module
103
// NOTE: Here you can call your desired module method
104
// like wponion_admin_page, wponion_metabox, wponion_taxonomy, etc...
105
// We are passing our module settings and our various field settings into our desired module output
106
// NOTE: in a more real world use, $this_field_instance would contain multiple fields and their settings
107
// instead of the one field shown in our documentation demo
108
wponion_metabox($this_module_instance, $this_field_instance);
109
110
}
111
112
}
113
114
}
Copied!
External Method
1
// CALL: post_submitbox_misc_actions action to load our render_this_field_externally function
2
// NOTE: you can render a single wponion field into any custom wp do_action location
3
// NOTE: you must write your own saving methods when rendering a wponion field externally
4
add_action('post_submitbox_misc_actions', 'render_this_field_externally');
5
6
// CREATE: render_this_field_externally to load our field and module routine
7
// NOTE: our wpo_field function can only echo a single field at a time
8
// you cannot pass multiple field types into the final echo ..->render()
9
function render_this_field_externally() {
10
11
// CREATE: our wponion_builder variable instance
12
// NOTE: we always create a wponion_builder variable instance to boot any wponion feature,
13
// then we determine what to do with that instance and its stored arguments
14
$this_field_instance = wponion_builder();
15
16
// CREATE: $this_field to our desired field type via our $this_field_instance variable
17
$this_field = $this_field_instance->select('my_field_id');
18
19
// ASSIGN: our general field features
20
// NOTE: these features are available to ALL field types but are considered general,
21
// like title, text descriptions, debug, etc...
22
$this_field->title(__('My Field Label')); // DEFAULT: false
23
$this_field->desc(__('My field description...')); // DEFAULT: false
24
$this_field->desc_field(__('My field description...')); // DEFAULT: false
25
// $this_field->debug(true); // DEFAULT: false
26
27
// ASSIGN: our unique field features
28
// NOTE: these features are ONLY available to this field type
29
// CONTROLS: this_feature_method | DEFAULT: value
30
// $this_field->this_feature_method();
31
32
// ASSIGN: our global field features
33
// NOTE: these features are available to ALL field types but are considered unique in their usage,
34
// like layout, custom css, dependency values and validation methods, etc...
35
$this_field->horizontal(true); // DEFAULT: false
36
$this_field->style('width: 100%;'); // DEFAULT: false
37
$this_field->help(array('content' => __('My field tooltip...'))); // DEFAULT: false
38
39
// ASSIGN: option values and their names to our select field dropdown
40
// MANUAL: ungrouped options
41
// $this_field-options(array(
42
// 'my_field_value_1_1' => __('My Field Label 1'),
43
// 'my_field_value_1_2' => __('My Field Label 2'),
44
// 'my_field_value_1_3' => __('My Field Label 3'),
45
// ));
46
// MANUAL: grouped options
47
$this_field->options(array(
48
__('My Field Group Label 1') => array(
49
'my_field_value_1_1' => __('My Field Label 1'),
50
'my_field_value_1_2' => __('My Field Label 2'),
51
'my_field_value_1_3' => __('My Field Label 3'),
52
),
53
__('My Field Group Label 2') => array(
54
'my_field_value_2_1' => __('My Field Label 1'),
55
'my_field_value_2_2' => __('My Field Label 2'),
56
'my_field_value_2_3' => __('My Field Label 3'),
57
),
58
));
59
// PREDEFINED: list
60
// $this_field->options('pages'); // VALUES: pages, posts, categories, tags
61
// CUSTOM: post type list
62
// NOTE: must use with $this_field->options('posts');
63
// $this_field->options('posts');
64
// $this_field->query_args(array('post_type' => 'product'));
65
// CUSTOM: taxonomy list
66
// NOTE: must use with $this_field->options('category or tags');
67
// $this_field->options('category');
68
// $this_field->query_args(array(
69
// 'option_key' => 'slug',
70
// 'option_value' => 'term_name',
71
// 'option_label' => '#[term_id] | [name] | ([count])'
72
// ));
73
74
// CALL: our single field render method
75
// NOTE: we can only echo a single field at a time
76
// you cannot pass multiple field types into echo ->render()
77
echo $this_field->render('my-custom-name-value', 'my_option_name');
78
79
}
Copied!

Output

$this_field->multiple(false);

Notes

There are currently no extra notes for this operation.
Last modified 1yr ago
Export as PDF
Copy link