admin管理员组文章数量:1277303
I created a custom post type called wasb_contact
which can be inserted and edited both from the backend and from the frontend (through a form I created).
The CPT has some custom meta fields which are saved by a function called wasb_contact_save_postdata
and invoked by the save_post_{$post->post_type}
hook. I would like this function to be invoked only when the CPT is created or modified from the backend and not also when it is created or modified from the frontend.
How can I do?
I created a custom post type called wasb_contact
which can be inserted and edited both from the backend and from the frontend (through a form I created).
The CPT has some custom meta fields which are saved by a function called wasb_contact_save_postdata
and invoked by the save_post_{$post->post_type}
hook. I would like this function to be invoked only when the CPT is created or modified from the backend and not also when it is created or modified from the frontend.
How can I do?
Share Improve this question asked Oct 14, 2021 at 8:49 icolumbroicolumbro 791 silver badge9 bronze badges 8 | Show 3 more comments1 Answer
Reset to default 1I would add some hidden input field to frontend form, and check for its presence in the save_post hook.
...
<input type="hidden" name="saved-on-frontend" value="1">
...
And then check for it in that hooked function:
function my_save_hook() {
if( isset( $_POST['saved-on-frontend'] ) ) {
return; // don't do anything ...
}
}
add_action( 'save_post_CUSTOM_POST_TYPE', 'my_save_hook' );
本文标签: hooksHow check if a post is saved from backend or frontend
版权声明:本文标题:hooks - How check if a post is saved from backend or frontend? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741268866a2368935.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
if ( defined( 'WP_ADMIN' ) )
? But this all depends on how you've set up the front end form I suppose. – Rup Commented Oct 14, 2021 at 10:41