dqol6556 2015-11-06 20:41
浏览 19
已采纳

插件下拉列表

I am developing a plugin, but I am clearly missing something.

My options for the check boxes I have created are saving, but I have also created a dropdown menu. The drop down menu doesn't save my selection for some reason. Thoughts?

//add for settings page    
add_settings_field("add-sizing", "Icon size", "add_sizing_function", "rcktcld-social", "admin_settings_section");


//register        
register_setting("admin_settings_section", "add-sizing");

        <?php function add_sizing_function() { ?>
            <select name="add-sizing">
                <option value="60" <?php selected( "add-sizing", 60 ); echo esc_attr( __( 'Select page' ) ); ?> >X-Large</option>
                <option value="48" <?php selected( "add-sizing", 48 ); echo esc_attr( __( 'Select page' ) ); ?> >Large</option>
                <option value="32" <?php selected( "add-sizing", 32 ); echo esc_attr( __( 'Select page' ) ); ?> >Medium</option>
                <option value="24" <?php selected( "add-sizing", 24 ); echo esc_attr( __( 'Select page' ) ); ?> >Small</option>

            </select>
        }
  • 写回答

1条回答 默认 最新

  • duanpie2834 2015-11-06 20:44
    关注

    They are probably saving fine, but you're not using the selected function properly: it compares two values for equality, and "add-sizing" is never equal to a number.

    You'll want to replace the first argument with the actual option value, like so:

    $add_sizing_setting = get_option( 'add-sizing' );
    
    ...
    
    <option value="60" <?php selected( $add_sizing_setting, 60 ); .....
    <option value="48" <?php selected( $add_sizing_setting, 48 ); .....
    ...
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答