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
- Get post meta in function hooked to transition_post_status
- How do I retrieve the slug of the current page?
- Most efficient way to get posts with postmeta
- Get posts by meta value
- Explanation of update_post_(meta/term)_cache
- How to extract data from a post meta serialized array?
- How to update custom fields using the wp_insert_post() function?
- Attaching taxonomy data to post with wp_insert_post
- Passing error/warning messages from a meta box to “admin_notices”
- How to save an array with one metakey in postmeta?
- WordPress is stripping escape backslashes from JSON strings in post_meta
- How can I get the post ID from a WP_Query loop?
- What is “meta_input” parameter in wp_insert_post() used for?
- How to update_post_meta value as array
- Adding meta tag without plugin
- What’s the point of get_post_meta’s $single param?
- What is the different between an attachment in wp_posts and an attachment in wp_postmeta?
- How to edit a post meta data in a Gutenberg Block?
- Sanitizing integer input for update_post_meta
- post formats – how to switch meta boxes when changing format?
- update_post_meta and update_field ony working when saving the post
- Lack of composite indexes for meta tables
- Get a single post by a unique meta value
- if get_post_meta is empty do something
- How we get_post_meta without post id
- How get post id from meta value
- What is the code to get the download link for a product in WooCommerce?
- Safe to delete blank postmeta?
- update_post_meta not saving when value is zero
- Content hooks vs User hooks
- Meta compare with date (stored as string) not working
- Trying to get custom post meta through Jetpack JSON API [closed]
- How to update/insert custom field(post meta) data with wordpress REST API?
- save_post + insert_post = infinite loop
- Restrict post edit/delete based on user ID and custom field
- get_post_meta returning empty string when data shows in the database
- publish_post action hook doesn’t give post_meta_data
- Remove WordPress.org Meta link
- Remove post meta keys
- How to access the post meta of a post that has just been published?
- Why time functions show invalid time zone when using ‘c’ time format?
- Why is get_post_meta returning an array when I specify it as single?
- How to update/delete array in post meta value?
- How to get all term meta for a taxonomy – getting term_meta for taxonomy
- wp_insert_post() getting slower the more posts
- Adding an assisting editor box to Post page
- Get updated meta data after save_post hook
- Manipulating post meta in the customizer
- delete unused postmeta
- Should I sanitize custom post meta if it is going to be escaped later?
- How do I retrieve multi-dimensional arrays from the wp_postmeta table, & display on a website?
- Front-end update_post_meta snippet displays white screen?
- Query between two meta values?
- Save both current and new version of post meta
- Get Advanced Custom Fields values before saving [closed]
- Better post meta efficiency?
- Give extra post-meta to RSS feeds
- How to get meta value in wp_attachment_metadata
- update_post_meta() not working in save_post
- WP REST API “rest_no_route” when trying to update meta
- How do I save each option in a multiple select menu as it’s own meta_key + meta_value pair?
- Clean up output added via wp_head()
- List posts under meta_value heading
- Why am I getting an infinite loop with have_posts?
- get_post_meta – get a single value
- delete value 0 in post meta [closed]
- Can I safely delete a record, manually, in the wp postmeta table?
- How to store post meta in an array?
- What action hook updates post meta?
- Can’t translate the post meta data (Date) in another language
- get_post_meta / update_post_meta array
- Post meta checkbox becomes unchecked occasionally
- wp_insert_posts Fatal error: Maximum function nesting level of ‘100’ reached, aborting!
- adding a URL to a post meta
- Set Primary category using the Yoast SEO plugin
- Exclude a category from the filed under list
- Short of raw SQL, can I query for multiple attachment metadata that have a given array key?
- How do I access post meta data when publishing a new post in Gutenberg?