Php 从HTML表单更新高级自定义字段
我正在使用一个定制的php代码,允许访问者通过创建帖子、使用表单向我的网站添加内容 它很好用 以下是我的PHP代码:Php 从HTML表单更新高级自定义字段,php,wordpress,insert,custom-post-type,advanced-custom-fields,Php,Wordpress,Insert,Custom Post Type,Advanced Custom Fields,我正在使用一个定制的php代码,允许访问者通过创建帖子、使用表单向我的网站添加内容 它很好用 以下是我的PHP代码: <?php if(isset($_POST['submit'])){ $err = array(); $err['status'] = true; $output = ""; if(empty($_POST['content'])){ $err['status'] = false; $err['msg'][
<?php
if(isset($_POST['submit'])){
$err = array();
$err['status'] = true;
$output = "";
if(empty($_POST['content'])){
$err['status'] = false;
$err['msg'][] = 'Le champ "Article" ne peut être vide.';
}
if($err['status']){
$insert = array(
'post_status' => 'publish',
'post_title' => htmlentities($_POST['title']),
'post_content' => htmlentities($_POST['content']),
'post_category' => array(11),
'post_author' => 999,
'tags_input' => htmlentities($_POST['tags']),
);
// $tags = $_POST['post_tags'];
$post_id = wp_insert_post($insert);
if($post_id != 0){
$user_meta_values = array(
'pseudo' => htmlentities($_POST['pseudo']),
'mail' => $_POST['mail']
);
$output = add_post_meta($post_id, "user_meta", json_encode($user_meta_values)) ? 'Article inséré avec succès.' : 'Une erreur est survenue lors de l\enregistrement.' ;
}
}
else{
foreach($err['msg'] as $k=>$v)
$output .= $v . '<br />';
}
}
?>
在我的HTML中:
<p><label for="text_ACF">ACF_texte</label><input type="text" name="text_ACF" id="text_ACF" value="" /></p>
ACF\u文本
我不知道如何做,如何参考我的高级自定义字段。有人能帮我吗
非常感谢
另外,我希望用户能够将图像上传到图像字段…我认为您只需要使用ACF功能
在您的情况下,它将类似于:
update_field(
'field_4fc5ab37e1819lol',
htmlentities($_POST['text_ACF']),
$post_id
);
要查找字段键,请转到字段组编辑屏幕,然后单击右上角的屏幕选项,如下图所示:
你肯定应该看看官方的这个功能,在那里你会发现一个完整的例子以及大量的usge的例子…你可能应该用wordpress来标记这个,除非你正在使用一些其他的cms,它碰巧也有
add_post_meta
。我确实在使用wordpress,任何想法@MarcBACF仅供WordPress@MarcBthanks回复。它工作,我必须包括在我的代码,并做一些调整!谢谢。。。顺便问一下,你知道我如何通过图像上传器实现这一点吗?如果你能帮忙,那就太好了@mmdwc对于图像字段,只需使用正确的值更新方法update\u field()
。例如,如果将图像字段设置为返回为ID
,则需要将函数与表示新附件ID的整数一起使用。。。
<p><label for="text_ACF">ACF_texte</label><input type="text" name="text_ACF" id="text_ACF" value="" /></p>
update_field(
'field_4fc5ab37e1819lol',
htmlentities($_POST['text_ACF']),
$post_id
);