我正在使用插件Wordpress User Frontend
编辑文章的标题和内容很好(我设法更改了它,以便编辑自定义文章类型),但不支持编辑自定义字段。因此,我有以下代码(不确定是否太长,必须放在pastebin上):
function wpuf_validate_post_edit_submit() {
global $userdata;
$errors = array();
$title = trim($_POST[\'wpuf_post_title\']);
$content = trim($_POST[\'wpuf_post_content\']);
$tags = wpuf_clean_tags($_POST[\'wpuf_post_tags\']);
$cat = trim($_POST[\'cat\']);
$post_location = trim($_POST[\'wpuf_post_location\']);
echo $post_location;
if (empty($title)) {
$errors[] = "Empty post title";
} else {
$title = trim(strip_tags($title));
}
if (empty($content)) {
$errors[] = "Empty post content";
} else {
$content = trim($content);
}
if (!empty($tags)) {
$tags = explode(\',\', $tags);
}
if (!$errors) {
$post_update = array(
\'ID\' => trim($_POST[\'post_id\']),
\'post_title\' => $title,
\'post_content\' => $content,
\'post_category\' => array($cat),
\'tags_input\' => $tags
);
$post_cf = update_post_meta($post->ID,\'location\',$post_location);
$post_id = wp_update_post($post_update);
//var_dump($post_update);
if ($post_id && $post_cf) {
echo \'<div class="success">Post updated succesfully.</div>\';
}
} else {
echo wpuf_error_msg($errors);
}
}
$post_cf
应更新从代码顶部抓取的位置字段(
$post_location
). 在回显字段时,它回显更新的字段,但在保存帖子时(
$post_id
?) 刷新页面时,自定义字段保持不变?
有人知道发生了什么事吗?我已经干了一个多小时了。