do_settings_fields()
Displays on the screen the option fields related to the specified section.
The function works in conjunction with other functions of the Settings API.
Note: usually, instead of this function do_settings_sections() is used to output the option fields associated with the section.
The function is similar to do_settings_sections(); it also outputs fields for a specific page and section, but these fields are not formatted in a table layout and are output as-is.
No Hooks.
Returns
null. Outputs the HTML code to the screen: the form fields.
Usage
do_settings_fields( $page, $section );
- $page(string) (required)
- Identifier of the admin page (page slug) on which to output the form fields. Must match the $page parameter from
add_settings_section( $id, $title, $callback, $page ). - $section(string) (required)
- Identifier of the section whose option fields should be output. Must match the $id parameter from
add_settings_section( $id, $title, $callback, $page ).
Examples
#1 Output the registered fields
Suppose we registered new options, added a section and fields to that section. Now, we need to display these fields on the plugin settings page in the admin panel, then use this function:
<div class="wrap"> <?php screen_icon(); ?> <h2>Primer plugin settings</h2> <form action="options.php" method="POST"> <?php settings_fields( 'primer_group' ); ?> <?php do_settings_fields( 'primer_page' ); ?> <?php submit_button(); ?> </form> </div>
For more info see API settings.
Notes
- Global. Array.
$wp_settings_fieldsStorage array of settings fields and their pages/sections.
Changelog
| Since 2.7.0 | Introduced. |