【发布时间】:2018-05-29 12:23:46
【问题描述】:
我创建了一个前端表单,用于创建一个新的自定义帖子类型。无论如何要从这个表单更新 ACF 元数据?
<?php if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] )) {
// Add the content of the form to $post as an array
$post = array(
'post_title' => $description,
'post_content' => $description,
'post_category' => 3, // Usable for custom taxonomies too
'post_status' => 'private', // Choose: publish, preview, future, etc.
'post_type' => 'door', // Use a custom post type if you want to
'post_parent' => $post->ID,
'post_name' => 'service',
'meta_key' => 'archive_job',
'meta_value' => 'red',
);
wp_set_object_terms($pid, $_POST['terms'], 'child');
wp_insert_post($post); // Pass the value of $post to WordPress the insert function
global $wp;
$current_url = home_url(add_query_arg(array(),$wp->request));
wp_redirect( $current_url );
// http://codex.wordpress.org/Function_Reference/wp_insert_pos
} // end IF
// Do the wp_insert_post action to insert it
do_action('wp_insert_post', 'wp_insert_post', 'add_post_meta' , 'update_post_meta');
?>
【问题讨论】:
-
可以,可以使用ACF提供的
update_field()函数:advancedcustomfields.com/resources/update_field
标签: php wordpress advanced-custom-fields