admin管理员组文章数量:1398795
I will use the wordperss REST API to submit a form that is part of SPA webapp made using vue. I have registered a custom post type to hold the submitted data, specifically I want to register some custom fields that will hold the submitted form fields.
I'm not sure on how to proceed, but after I've registered the post type, I think that I need to register a route register_rest_route()
to manage the data when they are submitted using a POST request, but how I save them? will the update_post_meta()
create the meta fields I want and wp_insert_post()
save then the custom post type?
UPDATE
The code I'm using to register the endpoint is the following:
function resgister_custom_endpoint(){
register_rest_route('mytheme/v1', 'p', array(
'method' => 'POST',
'callback' => 'add_new_place'
));
}
add_action('rest_api_init', 'register_custom_endpoint');
function add_new_place($request){
// save meta and post code
}
The meta fields I want to store with the custom post type I've created to manage the form are:
$_POST['fname'], $_POST['lname'], $_POST['email'], $_POST['place_name'], $_POST['place_type'], $_POST['place_address'], $_POST['place_city'], $_POST['place_zip_code'], $_POST['place_province']
They are all part of the form that is submitted from the user from the front-end.
本文标签: phpSubmit remote form to wordpress REST API and save data to custom post type
版权声明:本文标题:php - Submit remote form to wordpress REST API and save data to custom post type 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744573282a2613467.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论