我的插件表单代码:
function pp_settings_page() {
$pp_options = get_option('pp_options');
?>
<div class="wrap">
<h2>Post Products Settings</h2>
<form action="options.php" method="post">
<?php settings_fields('pp_options_group'); ?>
<table class="form-table">
<tr valign="top">
<th scope="row">Currency sign: </th>
<td><input type="text" name="pp_options[currency_sign]" value="<?php echo $pp_options['currency_sign']; ?>" /></td>
</tr>
</table>
<p class="submit">
<input type="submit" class="button-primary" value="Save changes" />
</p>
</form>
</div>
<?php
}
我尝试在模板文件中使用调用它
<?php $pp_options=get_option('pp_options');?>
和
<?php get_option('pp_options');?>
我错过了什么?
我没有看到任何处理表单提交的代码,更具体地说,是提取post变量并使用update_option 保存的代码
您的操作需要更改为设置页面URL,以便在发布时运行下一段代码,您可以将其放入pp_settings_page函数中。
if(isset($_POST['field_name'])) {
$field_value = $_POST['field_name'];
update_option('option_name', $field_value);
}