The reason for that is the save_post loop. When you call wp_insert_post, it triggers save_post and thus inserts the student meta.
what you can do is, to check if the post type is correct while inserting the meta.
like:
add_action( 'save_post', 'save_student_meta', 10, 2 );
function save_student_meta( $post_id, $post ) {
if ( 'student' !== $post->post_type ) {
return;
}
// Code gathering data form $_POST
Related Posts:
- Set default Custom Post Meta Value
- Check if Post Title exists, Insert post if doesn’t, Add Incremental # to Meta if does
- Execute action after post is saved with all related post_meta records (data)
- advanced custom fields update_field for field type: Taxonomy
- Add post meta based on another post meta value before publish post
- Get updated post meta on save_post action?
- Correct processing of `$_POST`, following WordPress Coding Standards
- Delete post meta conditionally after save post
- Compare old meta with new post meta
- Save post meta foreach loop
- troubles with get_post_meta (and saving it)
- Insert Custom Field Value
- Meta keys won’t add using wp_insert_post
- Get post meta after insert post
- Update post_meta post_name with the post ID from wp_insert_post after user register
- post_title in save_post action
- php wp_insert data on front using a form
- Auto save title as custom meta field value
- Save frontend submission form field as custom field
- get_post_meta() returns nothing in save_post, publish_post, wp_after_insert_post
- if condition from post_meta not working in save_post
- Getting author’s nickname as meta value
- How to update custom fields using the wp_insert_post() function?
- post formats – how to switch meta boxes when changing format?
- How get post id from meta value
- Safe to delete blank postmeta?
- get_post_meta returning empty string when data shows in the database
- publish_post action hook doesn’t give post_meta_data
- How to access the post meta of a post that has just been published?
- Should I sanitize custom post meta if it is going to be escaped later?
- Query between two meta values?
- Better post meta efficiency?
- List posts under meta_value heading
- loop through all meta keys with get_post_meta
- update_post_meta() whenever custom post type is updated
- post_status => publish not working
- Saving html into postmeta without stripping tags – safe?
- How to show Published date and/or Modified date
- wp_update_user isn’t instantly?
- How to use update_post_meta inside wp_trash_post
- “update_post_meta” not working in “wp_insert_post_data” hook
- update_post_meta, xml parser
- Pre insert data when adding new custom post fire a json error
- How to create a meta_query to get all posts with a specific meta data?
- Attaching taxonomy data to taxonomy with wp_insert_post
- hide posts with specific meta data from admin page
- Post MetaTable Overload
- Custom RSS Feeds & Post Meta Data
- Editing does not change post_name
- Compare string with post id in wpdb and do stuff when match is found
- $wpdb class updating meta_value using Ajax [closed]
- How to selected which tags to print, instead of printing the whole tag list?
- query posts and split meta information into separate div’s
- add unique string as custom-field to every post
- How do I insert a new meta key / value pair, but only if another meta key is present?
- “Cannot use import statement outside a module” JS error while adding a custom meta block?
- Gutenberg featured image checkbox – checkbox not correctly set on editing page reload
- How to properly use oneOf and anyOf in Rest Schema?
- Get the author meta adds now
- wordpress is_front_page() issue
- show ad after # paragraphs
- If ACF meta_key has meta_value
- Can wp_insert_post_data filter be used to save custom field data?
- How we can get “get_post_meta” of specific user who added it
- Repeated nav bar queries failing to be cached
- Randomizing Post Links Outside of Loop – No Author or Date
- help to decipher wp metadata
- SQL query – get a featured image’s alt / alternative text
- I can not display meta value in extras.php and template-tags.php
- update_post_meta() updating nested array in Multidimensional array with empty sub-array
- How do I list taxonomies that have upcoming events in WP? Is there a way to do this without having to query posts first?
- Sorting my posts on homepage my specific value in post_meta table
- Strict comparisons problem when using boolean post meta
- Why is the actual number of thumbnail images not matching what is store in an attachments metadata?
- Check if any meta on the post has value then display content
- Combine meta query and give a specific meta query a higher priority
- Get table parameter and save in meta value
- How can i show post views using specified post ID?
- How to add/update post meta to use in query?
- gettext localization is not working
- Rename image filename using ‘media_handle_upload’
- Update Post metafield of specific categories
- Custom post type meta fields missing on save_post_type
- Using Self Hosted Video URL With Custom Fields
- Multiple postmeta values to the same post_id/meta_key combination?
- get_post_meta not work in php foreach
- Why are my custom metaboxes not updating the post meta?
- Problem serializing single quote and double quote into post meta
- Storing post_meta fields in array
- Performace on 1 million plus meta fields vs 1 field with 1 million multi array
- Fetching array of postmeta with $wpdb and in_array conditional
- Piklist File Upload
- how to echo/display the custom field value in specific custom field name?
- update_post_meta() not working in bulk option
- How to update the ‘modified_time’ of a post ONLY when content is changed?
- Multiple If else statements on Search Result Page
- get_children filter with postmeta
- wordpress query making site very slow
- I read the postmeta and update it without changing it, then move on to the next record
- How to append $metadata[‘sizes’] to metadata when using ‘wp_generate_attachment_metadata?