admin管理员组文章数量:1414908
I have a front end form which creates a new post in a custom post type and adds some meta data to the post.
I am submitting the form by checking for $_POST
values in the same page in which form is created.
if( isset($_POST['save_form']) ){
$post_info = ''; // Set values to variables
$post_id = wp_insert_post( $post_info );
add_post_meta($post_id, 'my_key', $form_field, true);
}
Recently i have found that save_post_{post_type}
hook is fired whenever i submit this form. So all the fields in the front end form are available inside the callback function.
Is this default or have i done something wrong ? Should i change the saving method since posted values are available in save_post_{post_type}
hook.
I have a front end form which creates a new post in a custom post type and adds some meta data to the post.
I am submitting the form by checking for $_POST
values in the same page in which form is created.
if( isset($_POST['save_form']) ){
$post_info = ''; // Set values to variables
$post_id = wp_insert_post( $post_info );
add_post_meta($post_id, 'my_key', $form_field, true);
}
Recently i have found that save_post_{post_type}
hook is fired whenever i submit this form. So all the fields in the front end form are available inside the callback function.
Is this default or have i done something wrong ? Should i change the saving method since posted values are available in save_post_{post_type}
hook.
1 Answer
Reset to default 1Yes it is the default and yes you should be doing your work inside the save_post_{post_type} action. That's exactly what it is there for and is its intended use. Be careful, though, as this action is called every time the post is "saved" (created or updated)!
本文标签: savepost hook called on inserting new post from front end
版权声明:本文标题:`save_post` hook called on inserting new post from front end 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745186866a2646724.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论