Your metas need to be passed to wp_insert_post()
as an array like so:
// Insert the post into the database
$post["id"] = wp_insert_post( array(
"post_title" => $post["title"],
"post_type" => $cpt["custom-post-type"],
"meta_input" => array(
"custom-field-1" =>$cpt["custom-field-1"],
"custom-field-2" =>$cpt["custom-field-2"],
)
"post_status" => "publish"
));
https://developer.wordpress.org/reference/functions/wp_insert_post/#parameters
Related Posts:
- How to Upload CSV Data into Custom Post Type Data with Metabox programmatically
- Where to put my code: plugin or functions.php?
- Mini-Site Strategy
- How to set a fall back template for a custom post type in a plugin?
- Where to put archive-{post-type}.php
- Row actions not showing? Why?
- How to append element after thumbnail
- Dynamic Custom Post Type Plugin
- need advice on how to do a lists using custom post types – taxonomy vs postmeta
- Get rewrite slug of custom post type in template
- Admin notice not displaying
- How to Get Current Custom Post Type Selected Taxonomy Term (Not All Terms)
- What’s the difference between same wp functions get_posts(); functions in different form?
- How to customize a permalink (URL) structure?
- Query & Order posts by custom fields
- Use custom metabox to update automatically a post after a given date
- custom comments form for custom post type
- Problems wp_insert_post and save_posts filter
- Redirect to another page using contact form 7? [closed]
- detect your custom post type in WordPress
- Show current custom taxonomy
- How exclude or skip post type with get_next_post_link
- WordPress: Custom User Role cannot access Custom Post Type | “Sorry, you are not allowed to access this page”
- How do I add custom HTML to the content of an archive page’s posts?
- How to Use Custom Meta Field Instead of CPT Title in Post URL
- Validate Custom Post Type fields
- Front end create custom post types
- Custom post type page with parameter
- Not Able to Add New Class To CPT Attachment Image
- Change Dropdown jQuery to show/hide but with default place holder that shows all
- Custom post category name showing empty
- How to store the third party script with HTML code in the wordpress custom input field?
- How to show the post which checkbox is not selected
- How to get the custom post data using post id in WordPress?
- Is it possible to get the specific content on the search page?
- Get next and prev item from custom WP_Query and Custom Post Type
- Error 404 change permalink term custom term taxonomy
- Plugin Development using classes – Public & Private Callbacks
- I have a random letter appearing before my content. Where to start looking for the cause?
- programmatically generated custom post type is created more than once
- Visualize info in just custom post_type in theme
- cpt not display inside nav menu
- How to use posts as tabs in a custom page?
- Custom Post Type has wrong label and is not found when called by a loop
- Front End users account with lots of user Roles (not Woocommerce)
- Custom post type that lets users create a set of posts?
- call a function when insert and update a custom post type
- Not Able to Get Custom Post Type in Single and Single-custom-post-type
- How to develop custom URL redirection
- Loop carousel slider in wordpress
- Issue on Counting CPT’s Under Taxonomy Term
- Not Able to Display Metabox Saved Checkbox and Selected option After Save/ Update
- How to manage wordpress knowledge base/wiki/posts collections
- Need some hints for my own WP theme development
- How to dynamically register custom post type
- How to build a complex page structure
- Date archives for custom post type
- If featured image doesn’t exist, show post content
- Append taxonomy terms as class names in markup?
- Using WPAlchemy metabox values in another metabox
- adding .current* tags to custom post types and taxonomies
- GravityForm: Populate Dropdown with custom post type [closed]
- How to output wordpress custom tags separated by comma?
- Custom Post Type rewrite
- Dynamic page outside WordPress
- Changing number of posts per page on CPT-archive.php, have tried 20-30 code chunks so far
- Help need making decision. Ads rotating site on wordpress
- I need to add endpoint for wordpress categories
- Getting meta in editor plugin, and event triggering issue
- Display a grid of taxonomy terms at root taxonomy page
- Hide a widget inside a div on specific type of post
- How to use TinyMCE Editor for one of my custom post meta field?
- How to import a custom MySQL DB table into a WordPress custom post type
- Deleting taxonomy terms and relationships on a custom post_type when a user is deleted
- Foreach inside shortcode not working as planned
- Warning: Invalid argument supplied for foreach() [closed]
- Custom post type isn’t working
- Add additional field to custom post_type
- Save Multiple Metabox values
- Using wp_query to modify the loop in index.php for a CPT
- Create short URL with auto 301 redirect
- Types plugin custom post add_action hooks
- Different column width in 2 rows with bootstrap and custom post types-different classes needed
- How to stop the custom post type URL from the google search?
- Add extra elements to the_post in a custom post_type
- Warning , Use of undefined constant PLUGIN_PATH?
- Custom Post Type archive page listing a 404 or single post
- Too many revision when post status is changes [duplicate]
- Custom Taxonomy – fields
- Imported posts for cpt are imported as scheduled, not published [SOLVED]
- Custom Post type plugin is using theme single.php and style.css
- CPT post doesnt shows tags and category on backend admin page
- How To Display Category list from Portfolio post type plugin?
- Registering an optional custom post type from a plugin
- Get month and day from a Date Picker custom field
- Generate custom RSS from a plugin
- is_singular won’t call my functions?
- Inserting two categories
- Comments are not working on Custom Post Type
- Custom post type is_singular condtional not working when managing sidebar display