从不同页面的前端更新post-meta



我正在尝试更新指定posttype的post内容。出于某种原因,它不起作用。

我已经成功地在邮件页面的后端使用了代码进行编辑。现在,我也想在前端为员工使用它,以便进行快速管理。

$id已正确转移。我用了这个代码

这是我的代码片段:

<?php $id = $_GET['car']; ?>
<?php
if ( isset( $_POST['submit'] ) ){
$fields = [
'car-highlight-2',
];
foreach ( $fields as $field ) {
if ( array_key_exists( $field, $_POST ) ) {
update_post_meta( $id, $field, sanitize_text_field( $_POST[$field] ) );
}
}}
?>
<form method="post" action="">
<tr>
<td><input type="text" id="car-highlight-2" name="car-highlight-2" value="<?php echo get_post_meta($id, 'car-highlight-2', true); ?>"></td>
</tr>
<input type='submit' value='save' />
</form>

我忘记在输入中添加name="submit"。

最新更新