我正在尝试创建一个简单的复选框设置,在主题设置页面中切换博客文章中的某个部分。
不幸的是,它没有保存复选框设置。我选中了这个框,当我刷新页面时,它再次被取消选中。要么是它没有保存设置,要么是checked函数无法工作。我是不是遗漏了什么?
function theme_option_settings(){
register_setting( 'prev-next-setting', 'prev-next' );
add_settings_section( 'blog-section', 'Blog Section', 'change_blog_layout_section', 'theme-options' );
add_settings_field( 'show-prev-next', 'Show Previous/Next Post Section', 'show_prev_next_field', 'theme-options', 'blog-section' );
}
function change_blog_layout_section(){
echo "Change the blog layout section";
}
function show_prev_next_field(){
echo get_option( 'prev-next' );
echo "<input type='checkbox' id='prev-next' name='prev-next' value='1' ".checked(1, get_option('prev-next'), true)."/>";
}发布于 2018-10-10 13:48:34
我设法弄明白了。这是因为在模板页面上,我输出的表单忘记了包含settings_fields函数,所以它没有保存设置。我将下面的代码添加到该页面中,然后它开始工作了:
<?php settings_fields('prev-next-setting'); ?>https://wordpress.stackexchange.com/questions/316235
复制相似问题