我是wordpress插件开发的新手。在这里,我希望用户从复选框中列出的所有注册帖子类型中检查他/她所需的帖子类型。下面的代码显示所有已注册的帖子类型,但当用户选中该框并保存更改时,页面将刷新,但未选中该复选框。function fbog_options_page() { add_submenu_page( 'tools.php', 'FB Custom Open Graph', 'FB Custom Open Graph', 'manage_options', 'cpn-fbog-settings', 'cpn_fbog_options_page_html', 20 );}add_action( 'admin_menu', 'fbog_options_page' );function cpn_fbog_settings(){ register_setting('fbog_settings_group', 'fbog_settings');}add_action('admin_init', 'cpn_fbog_settings');function cpn_fbog_options_page_html(){ global $fbog_options; $fbog_options = get_option('fbog_settings'); ob_start();?> <div class="wrap"> <div class="container"> <div class="row"> <div class="col-md-12"> <center><h1>Welcome to Custom Facebook Open Graph</h1></center> <h3>Choose the post types to display the "Custom Facebook Open Graph".</h3> <form method="post" action="options.php"> <?php settings_fields('fbog_settings_group'); ?> <h4>Check the Post Types</h4> <p> <?php $post_types = get_post_types(); foreach ($post_types as $post_type) { ?> <input id="fbog_settings_<?php echo $post_type; ?>" name="fbog_settings[post_types]" type="checkbox" value="1"<?php checked( 1, $fbog_options['post_types'], false ); ?> /> <label class="description" for="fbog_settings[post_types]"><?php _e($post_type, 'fbog_domain'); ?></label> <br /> <?php } ?> </p> <p class="submit"> <input type="submit" class="button-primary" value="<?php _e('Save Options', 'fbog_domain'); ?>" /> </p> </form> </div> </div> </div> </div> <?phpecho ob_get_clean();}
1 回答
慕仙森
TA贡献1827条经验 获得超7个赞
您的代码是正确的,除非您没有保存正确的帖子类型。
更改此行:
<input id="fbog_settings_<?php echo $post_type; ?>" name="fbog_settings[<?= $post_type ?>]" type="checkbox" value="1"<?php checked( 1, @$fbog_options[$post_type]); ?> />
- 1 回答
- 0 关注
- 67 浏览
添加回答
举报
0/150
提交
取消