How to mark an option as selected

What you are looking for is the selected() function. Your updated option should look like this: <option value=”<?php echo $category->cat_ID; ?>” <?php selected($option, $category->cat_ID); ?>> <?php echo $category->cat_name; ?> </option> // EDIT Oh, and BTW, in your particular case you might want to use the wp_dropdown_categories function, I guess. That would be: wp_dropdown_categories( array( ‘selected’ … Read more

Can I use the different settings sections over different pages using the save options group?

The solution is to merge existing options before saving options in case not all options are presented on the page we are about save. So in the end of $sanitize_callback in register_setting function just before I return the data I call below function where $existing are all existing options saved in database. function merge_options( $existing, … Read more

WooCommerce “Save Changes” button appears inside custom settings

Ok, the fix is quite easy, although not obvious at all. All we need to do is just add array( ‘type’ => ‘sectionend’, ‘id’ => ‘test-options’ ), to the end of the settings group. So the final function should look like this: add_action( ‘woocommerce_settings_start’, ‘wpse8170_register_settings’ ); function wpse8170_register_settings() { global $woocommerce_settings; $woocommerce_settings[‘test’] = array( array( … Read more

add function to saving change on Options Pages

To execute a task after a option has been updated, you can use updated_option action hook: add_action( ‘updated_option’, ‘updated_option_callback’, 10, 3 ); function updated_option_callback( $option, $old_value, $value ) { //Do something } Also, you can use update_option_{option-name} specifically for each option. For example: add_action( ‘update_option_new_option_name’, ‘update_new_option_name_callback’, 10, 2 ); function update_new_option_name_callback( $old_value, $value ) { … Read more

Custom options page checkbox will not save, despite working with text

Don’t comment out your validation code remember you are using it to validate the data, so its returning nothing right now, so its saving nothing, try this: add_action(‘admin_bar_menu’, ‘make_parent_node’, 999); function make_parent_node($wp_admin_bar) { $args = array( ‘id’ => ‘test1234’, // id of the existing child node (New > Post) ‘title’ => ‘test’, // alter the … Read more

Select dropdown not showing selected value php

The reason your $item == $option condition is always failing is because of the way PHP compares floats! Try the following instead: echo “<option value=”$item”” . selected (abs ($item – $options) <= 0.01, true, false) . “>$item</option>” ; See Comparing floats for more info.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)