WordPress setting with select – where is my mistake?

Question

I have two option callbacks in my plugin, one with a ckeckbox and one with a select field. The first one is working perfectly, the second not. The select field doesn’t save its value. I double checked the code which registers the two settings, I assume my mistake is somewhere in the callback.

Any ideas?

Checkbox (works):

public function myplugin_post_menu_cb() {
    echo '<input type="checkbox" name="' . $this->option_name . '_post_menu' . '" value="1" "' . checked(1, get_option('myplugin_post_menu'), false) . '" />';
}

Select (doesn’t work):

public function myplugin_admin_bar_cb() {
    echo '<select name="' . $this->option_name . '_admin_bar' . '">';
        echo '<option value="1" "' . selected( get_option('myplugin_admin_bar'), 1 ) . '">1</option>';
        echo '<option value="2" "' . selected( get_option('myplugin_admin_bar'), 2 ) . '">2</option>';
    echo '</select>';
}

Thanks for the help.

--------------------------------------------------

>>> Share a link to this question, just copy and paste the code bellow on your web page <<<

<a href="https://www.wptricks.com/question/wordpress-setting-with-select-where-is-my-mistake/">

WordPress setting with select - where is my mistake?</a>
0
, , , , t3chernobyl 3 weeks 0 Answers 12 views 0

Leave an answer