0

I am creating catagory checkbox select.

My code to render the category checkbox is:

// CHECKBOX - Name: plugin_options[chkbox2]
function setting_chk2_fn() {

    $options = get_option('plugin_options');
    $categories = get_categories('orderby=name');  
    $wp_cats = array();  

    foreach( $categories as $category_list ) {  
        $wp_cats[$category_list->cat_ID] = $category_list->cat_name;  
    }  

    foreach( $wp_cats as $v ) {
        echo "<input type='checkbox' name='plugin_options[chkbox2]' value='{$options['chkbox2']}' />";
        echo $v;
        echo '<br>';
    }
}

All catagories are rendered properly but it is not saving in database. Thanks for reading

3
  • 2
    The reason is that there is no code to save anything in the database. Write that code.
    – fuxia
    Jan 20, 2014 at 8:56
  • @toscho the code register_activation_hook(FILE, 'add_defaults_fn'); function add_defaults_fn() { $tmp = get_option('plugin_options'); if((!is_array($tmp))) { $arr = array( "dropdown_font" => "#ffff", "catagory" => " ", "chkbox2"=>"Uncatagorised ", "text_size"=>"17px", "background_color"=>"red", "label"=>"Hot", ); update_option('plugin_options', $arr); } }
    – ashraf
    Jan 20, 2014 at 10:51
  • 2
    @ashraf please update your question. That would be more helpful.
    – sri
    Jan 20, 2014 at 12:54

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.