I had the same problem, and here what works for me:
function journal_check_cats_callback() {
$options = get_option('journal_theme_blog_2_col');
$pag = journal_theme_blog_2_col;
$_cats = get_terms( 'category' );
$html="";
foreach ($_cats as $term) {
$checked = in_array($term->term_id, $options) ? 'checked="checked"' : '';
$html .= sprintf( '<input type="checkbox" id="%1$s[%2$s]" name="%1$s[]" value="%2$s" %3$s />', $pag, $term->term_id, $checked );
$html .= sprintf( '<label for="%1$s[%3$s]"> %2$s</label><br>', $pag, $term->name, $term->term_id );
}
$html .= sprintf( '<span class="description"> %s</label>', '' );
echo $html;
}
Related Posts:
- How to pass arguments from add_settings_field() to the callback function?
- esc_url not working within add_settings_field callback
- How can one utilize a variable as a callback function name for add_settings_field
- How to validate register settings array
- settings_fields doesn’t appear to be running
- Stop post being published
- Settings API callback function inserts html quotes from nowhere
- call_user_func_array expects parameter 1 to be a valid callback
- Code works, but warning about call_user_func_array() appears
- custom-background callback breaks media uploader
- Category callback box problem
- I need help with this error [duplicate]
- Trouble with WordPress Settings API: Form Submits When Fields Called Directly, Fails When Using Callbacks
- Settings API with arrays example
- Add multiple custom fields to the general settings page
- Settings API vs Theme Customizer
- “Error: Options Page Not Found” on Settings Page Submission for an OOP Plugin
- Is get_option function cached?
- How to pass variable to add_settings_section() callback?
- What are the advantages to the Settings API?
- Custom Post Type Settings page, choose page to display archive
- Run function AFTER theme options are saved?
- Where to store plugin settings fields
- current_shortcode() – detect currently used shortcode
- Trigger custom action when setting button pressed
- How can I save a multiple select array with the settings API for a plug-in options page?
- Settings API in Multisite – Missing update message
- How to Use Checkbox in Custom Option Page Using The Setting API
- How should one implement add_settings_error on custom menu pages?
- WordPress Settings API, Implementing Tabs On Custom Menu Page
- wp_editor() fields on Theme Options Page not saving
- How do I add settings to the Background Options Page?
- Settings API – adding setting fields dynamically?
- wp enqueue script using scripts from cdn with a safety callback
- Hook if somebody saves plugin options?
- Accessing plugin settings in gutenberg
- Difference between Option_Group and Option_Name in Register_Settings
- Can an action callback prevent the parent from continuing execution?
- What’s the best method for emptying an option created with the Settings API?
- Image upload callback in new 3.5 media
- WordPress REST API – Permission Callbacks
- Settings API – sanitizing urls, email addresses and text
- Settings API – easiest way of validating checkboxes?
- Default value for add_settings_field
- Where can I find a schema of wordpress plugin core architecture?
- Add your own settings page for plugin
- Settings API – creating reusable form elements?
- Adding an html editor to plugin settings page
- add static page to reading settings for custom post type
- Settings API – changing add_settings_field() output?
- Using a private method as an action callback from within a class
- How to check if which hook triggered the call to a function?
- How to display an admin notice after updating plugin settings?
- Callback for wp.autosave.server.triggerSave();
- Add settings fields on options discussion admin page
- How do I hook an Ajax request into a PHP callback?
- Which to use to execute code during the saving of a plugin settings page?
- WP showing “warning: call_user_func_array()”, What to do?
- How do I flush the rules after saving settings using the Settings API?
- Flush_rewrite_rules not working when settings updated
- Failing to open advanced-cache.php which is breaking Media Library
- Nonce in settings API with tabbed navigation
- register_setting() vs add_option()
- Where to store some per-template preferences?
- gutenberg dynamic block is returning 404
- How to Loop Plugin Option Field Set?
- Settings API – save an array of options as one setting (array_push?)
- Hooking a callback into the code within a Gutenberg block
- Add_settings_field() parameterizing callback?
- Validate an option array
- Default WordPress settings API data sanitization
- How to pass variable via $callback_args for add_meta_box
- Save and retrieve custom plugin options value
- How should I use register_setting, add_settings_section, & add_settings_field in my plugin’s options page?
- Secure my “add_settings_field” translation?
- Using tabs for wordpress plugin
- How to handel multiple checkbox field in the admin settings page with Settings API
- Custom plugin settings: clicking “save changes” does not display success message
- Dynamic settings fields with Settings API
- How to use the settings API to set multidimensional arrays
- Settings API repeater fields
- ob_get_clean returns empty string, ob_get_flush outputs string
- replace current_page_item class in menu
- How can I include a setting that has a variable number of values in a settings page using register_setting?
- How do I use the control callback when creating a simple dashboard plugin
- Setting ‘autoload’ to ‘no’ with Settings API
- Add Settings to Custom Post Type
- do_settings_sections() doesn’t escape quotes
- Saving Plugin settings to the database
- Theme customizer: How do you grab the value later?
- How to Save Different Settings Options Using Settings API and/or the Theme Optimizer
- Serialized settings in rest api
- How to get control choices from $setting object passed to sanitize_callback
- Can’t output do_settings_sections . Can’t understand why
- How to add an export function to a custom Option Theme Page
- Update term count using a callback function
- Add Admin Menu Inside Construct or Init
- Import / Export Settings API fields values?
- Why won’t register_setting() create a setting?
- Settings API erases itself?