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
- Get posts by meta value
- post formats – how to switch meta boxes when changing format?
- update_post_meta not saving when value is zero
- Restrict post edit/delete based on user ID and custom field
- Remove post meta keys
- wp_insert_post() getting slower the more posts
- delete unused postmeta
- Should I sanitize custom post meta if it is going to be escaped later?
- wp_insert_posts Fatal error: Maximum function nesting level of ‘100’ reached, aborting!
- Using Advanced Custom Field (ACF) to insert meta description on each page
- How to add meta tag to wordpress posts filter?
- Metabox Data not being saved [closed]
- Options to get my custom post type metadata via the WordPress API
- Generate an Email address from that of the Post Author
- post_status => publish not working
- How to get the total number of meta_values based on a custom post type?
- Does “update_post_meta” check if value is the same before updating?
- Add a meta value if admin , editor or any other user have open a post in edit mode
- Finding the page id
- WP_POSTMETA – What do these values mean inside the data structure?
- Update Line Item Meta Data – WooCommerce API
- Unset field from an array not working as expected
- Update post_meta with WooCommere variation data
- What type of index should I use for postmeta?
- Meta function issue
- Saving zero as meta value
- Get a row from a separate table by matching a posts meta_key to a tables ID column
- get_post_meta is showing file url in url bar
- Should I save this mulit dementional arary as one post meta?
- How to check if a post meta key/value pair already exists for a specific post
- Reset/delete post views meta/custom field after X hours or minutes or seconds
- Have lots of meta for posts, is it better to get at all at once or each individually
- Query posts WITHOUT a custom meta field
- Add box with custom per-page properties
- get_post_meta not working when variable used for post ID
- Update post meta dynamically
- Duplicate rows in meta table, any known relations in WC?
- update_post_meta not working in foreach
- Is it safe to add a new field to meta_value field?
- Need a SQL query to update meta_key=’_price’ with value in meta_key=’_regular_price’
- Display current user’s custom post meta in sidebar
- Why is my get_post_meta not properly calling the custom field when attempting to embed a YouTube video?
- add_post_meta doesn’t work
- How to get single value from get_post_meta() array of values?
- Editor meta box Showing but not saving
- wordpress update multiple posts post meta
- get_template_part() isn’t loading author information
- get Insert id for meta field
- How do I add a fixed value to get_post_meta();?
- Is there a way combine posts meta_name?
- Add post’s category as a meta tag to the post
- Format meta_value [closed]
- How to check post meta isset or not empty during publish/save post?
- Count Post and Page Views based on meta_value Using Shortcode in Dashboard Widget
- How can i set media attachments to the author of the post or page for already existed posts with attachments
- Removing Malware
- How to get posts by meta value as multi-dimensional array?
- After updating the custom post type, metafields disappear from the post.php edit menu, how do I fix it?
- URL from get_post_meta() is broken my URL
- Updating failed message when a wp_insert_post function is hooked to save_post hook
- get_post_meta and add_post_meta not working
- Export media library with metadata and import into new blog
- Move Entry Meta Above Title in Archives (Genesis + Brunch Pro)
- how to query posts using value in meta post array
- Why doesn’t wp_oembed_get() for the video post format not work?
- Custom Meta Fields that are Echo’d are removed on post update?
- How to get a post meta value and pass that to update_option when a post is created or updated?
- How to add dynamic content in title and meta description in wordpress theme for homepage, post page, category, tag and pages
- How to call get_post()?
- add_post_meta only adding 1 character
- Posts with no meta field do not appear when sorting by meta field
- How do I delete element from a serialized array upon deletion of a post?
- Update fields with post object and custom tax with wp_insert_post
- Fetch post meta data on POST request
- Get meta information from post parent
- Counting number of identical meta keys
- query with custom field
- Using Form to alter PHP variable [closed]
- Chance post id into post name