Ultimately the solution that I found was to use global $post; to retrieve the current post’s ID.
Immediately after wp_insert_post( $new_cpta );
above, I added
global $post;
$currentid = $post->ID;
Then I was able to update the post meta for the correct post with $currentid
in place of $post_id
.
Related Posts:
- wp_insert_post() getting slower the more posts
- Efficient way to save a lot of meta data
- How to use wp_insert_post to update meta box?
- wp_insert_post bulk import 500 server error
- update_post_meta, xml parser
- Combining wp_insert_post() and update_post_meta()
- Update post_meta post_name with the post ID from wp_insert_post after user register
- Insert post programmatically and decide to tweet or not to tweet
- How to update custom fields using the wp_insert_post() function?
- Faster way to wp_insert_post & add_post_meta in bulk
- Check if Post Title exists, Insert post if doesn’t, Add Incremental # to Meta if does
- Is there a downside of using wp_defer_term_counting?
- wp_insert_post extremely slow on big table, direct query very fast
- What is “meta_input” parameter in wp_insert_post() used for?
- wp_insert_post add meta_input
- tax_input not working wp_insert_post
- See error message from wp_insert_post function?
- Adding post thumbnail in programatically inserted post
- can’t edit post_modified in wp_insert_post (bug?)
- advanced custom fields update_field for field type: Taxonomy
- wp_insert_post incorrectly escapes HTML comments when they include tags
- What is considered the post’s creation date for wp_insert_post?
- Insert new term during new post creation
- tax_input argument for wp_insert_post()
- How can I stop wp_update_post messing up HTML example code?
- How to insert custom function into wp_insert_post
- wp_insert_post does not write my post_name
- Is there a way to fire other functions from wp_insert_post
- Organizing uploaded media with wp_insert_post() and wp_handle_upload according to time parameter
- wp_insert_post to schedule a post – but nothing happens?
- post_date_gmt and post_date [duplicate]
- Get data from wp_editor()
- Replace string with post_name on sidebar
- Inserting Hundreds of Thousands of Posts at Once
- Visual Editor – Colorize Shortcodes
- wp_insert_post insert a post but return 0
- How to update post parent?
- wp_insert_post returns int(0)
- Contact Form 7 to featured image
- Conditionally set post_content in wp_insert_post
- wp_insert_post -> post_content not showing
- after wp_insert_post need to get the post id
- Could not get post ID from wp_insert_post()
- Creating New Page with WP_INSERT_POST Issue
- wp_insert_post is not creating revision in database
- Set default Custom Post Meta Value
- wp_insert_post issue
- Adding custom fields (post meta) before/during wp_insert_post()
- add_menu_page Callback Function: Skip page content?
- update post meta for checkbox in the admin when inserted in the front-end
- WPML – Set language of inserted post
- using wp_insert_post inside of custom meta box
- Check if post is added manually or through wp_insert_post()
- How to upload multiple image using wp_insert_post
- When User Meta amended update Title and Slug of Post programatically
- Attaching taxonomy data to taxonomy with wp_insert_post
- keep wp_insert_post from adding duplicates
- Update post meta does not serialize array
- Programmatically create a post once a day
- wp_insert_post custom type and custom taxonomies
- Where to call wp_insert_user() and wp_insert_post() from?
- wp_insert_post at same time as saving post results in 502 Bad Gateway
- wp_insert_post alternatives for faster process
- WP-CLI –meta-input error: Warning: Invalid argument supplied for foreach()
- $user_id = wp_insert_user( $userdata ) Not working no errors
- $wpdb->insert() does not insert fields
- How to handle this specific case of custom post type?
- Insert multiple posts as parent of the first
- Insert data from custom created PHP page into wp_postmeta table
- Save the Post ID from wp_insert_post($post); into a text file?
- wp_insert_post removes information when updating
- Bug in wp_insert_post script and form, probably something simple I am not seeing
- Setting Post Date Returning “Notice: A non well formed numeric value encountered”
- wp_insert_post creating duplicate post with Safari
- Insert Custom Field Value
- “transition_post_status” action creating two post with wp_insert_post
- wp_insert_post fails at return statement (nothing is returned to the caller, the error displayed is: The Link You Followed Has Expired)
- XML FOLDER – wp_insert_post – how to assign XML variables to post
- Cannot insert HTML content even removing kses filters
- get_page_by_title() not working as expected
- wp_insert_post inside save_post adds wrong metadata to inserted post
- Meta keys won’t add using wp_insert_post
- Insert Multiple Posts from JSON Results
- How can I automatically add a post with Latin characters?
- insert category from form in a post
- How to insert post from external php file?
- How to Create Content Remotely
- Bulk insert posts is really slow and skips entries
- php wp_insert data on front using a form
- Changing wp_insert_post() location
- wp_insert_post questions
- wp_insert_post does not insert string with apostrophes correctly
- add_post_meta displays in admin edit area
- Automatically add another subpost of the same parent when a subpost is saved
- Setting a featured image while creating the post
- foreach $FILES create post how to
- WooCommerce wp_insert_post action firing on every save
- wp_insert_post and title not utf8 inserts with empty title?
- Update fields with post object and custom tax with wp_insert_post
- Set post_parent from URL params in post-new.php