Use wp_insert_post() and add_post_meta(), like this:
// insert the post and set the category
$post_id = wp_insert_post(array (
'post_type' => 'your_post_type',
'post_title' => $your_title,
'post_content' => $your_content,
'post_status' => 'publish',
'comment_status' => 'closed', // if you prefer
'ping_status' => 'closed', // if you prefer
));
if ($post_id) {
// insert post meta
add_post_meta($post_id, '_your_custom_1', $custom1);
add_post_meta($post_id, '_your_custom_2', $custom2);
add_post_meta($post_id, '_your_custom_3', $custom3);
}
Related Posts:
- Create a custom archive page for a custom post type in a plugin
- Remove custom post type slug from URL
- Admin Filter – Add Post Type Description on Post Type Page
- Mandatory excerpt for custom post type
- List page for custom post type?
- Display several random posts, but make sure a condition is met
- Custom Postype Query showing only 10 results should show 23 results
- Custom post type’s get_permalink returns wrong url
- How to hook get_terms() to only show count of posts that have custom meta
- how do I display a featured image in a post type?
- QTranslate for Custom Post Type [closed]
- Need help with complex custom post type setup
- WordPress monthly archive links result in 404
- custom_post_type with has_archive doesn’t change permalink
- Not sure why my custom post meta field isn’t saving
- Remove taxonomy slug when not assigning taxonomy with custom post types
- Add extra parameters after permalink?
- wp is not defined error using wp.media to create a custom image uploader
- Custom taxonomy template not working with simple loop. Multiple CPT using the same taxonomy
- Need post_type_archive_title function but in ‘single’
- add_rewrite_rule and how to get the custom post into the worpress loop the correct way
- What is the use of a custom taxonomy?
- Return array of categories to php function for current post
- How do I get the permalink structure to work like this?
- Hierarchical Custom Post Types – Show only parent on tax archive?
- Post Submission from frontend with custom field isn’t working
- How to show customized activity for custom post types in buddypress activity loop?
- Sorting multiple custom post types without a meta key/value pair by sort order
- Remove fields on media uploader for custom page type – not working for “From Computer” or “From Url” tabs?
- wp_query check if integer exists in custom field’s array
- WP Storing postmeta into revisions
- Custom post registration causing errors
- Meta Query Filtering not working on Custom Meta Box using Radio Buttons
- How to clone Media custom post type?
- WordPress custom taxonomy, posts urls
- Import data from CSV with custom taxomony empty
- Custom Post Type Loop with Query Var
- Full Custom Post Type List Organised by two Taxonomies
- Custom post type submenu capabilities – custom plugin
- Template for all categories of a custom post type?
- Include related custom fields from one post type in another post type’s JSON feed
- Is there a way to establish parent/child relationship in WP menu links exclusively?
- Custom filter function not working with Custom post type
- Meta-Boxes for CustomPostType cause PHP Errors and Notices in “Add New” view
- custom post type metaboxes not saving
- How can I add a custom field to an existing custom post type?
- Help With Warning on creating new Post types?
- Custom post type, have only my meta boxes
- detect your custom post type in WordPress
- Add tags to custom post type without menu link
- List categories, subcategories and posts from custom taxonomy and custom post type
- Shortcode is displaying the content on top of the page [duplicate]
- Distribute Custom Post in different pages
- How to list top 5 custom post types depending on comments?
- How can I get some of a posts meta data whilst it is still inserting?
- Archive page for custom post type and custom taxonomy
- Custom loop to query posts with no featured image and/or no post editor content
- Custom post type ‘Show on screen’ didn’t apply to number
- How to display posttypes and taxonomy in standard posts, not in a separate label?
- Creating an Events Feed with Sub Pages/Posts for Each Event
- Show 10 newest post for each value of a custom taxonomy
- Problem with custom loop navigation inside the blog page
- WordPress giving me the index
- How to customize custom post type’s list table?
- Query to show post current day
- Using ACF values in nested WP queries for CPT with date values in the past
- SELECT custom post type and its meta in SQL
- Trying to list years (for a filter) but not all years display
- Custom post type defaults to index.php for archive page
- customize Dokan multi vendor: how can i set every Dokan as child of another dokan?
- Why do my custom post types stop displaying over time?
- CPT tags not showing when editing post
- WP_Query for custom taxonomies showing posts from non-specified terms?
- Persist meta box choices throughout all posts of same post type
- Rewrite of Custom Post Type doesn’t work with dynamic data
- Make pagination work as a carousel (custom query)
- Assign for all post of a post type a specific single-post template
- Display custom tax in “while” loop
- Custom post type archive false is not compatible with breadcrumbs
- Overriding a CPT template file through functions.php
- Wrong post ID in meta box callback
- Custome post type “tags” pick default archive instead of custom post type archive
- help me to display featured image of specific post by post id
- How do I retrieve the title of a term of a custom post type with custom taxonomies?
- 404 custom post type
- Displaying WordPress Parent field in child post
- Custom post tag images not displaying with ACF
- Single page archive – get coresponding taxonomy and terms
- Custom WordPress URL
- How to assign custom post template to its custom taxonomy terms
- Excluding top level from taxonomy and post loop
- Paginating custom query on category template
- Get a list of categories ids
- Custom taxonomy archive not showing posts of certain child taxonomies
- Custom Post Type Loop breaking php
- Styling first post using Advanced Custom Fields
- Add a background image into a post [closed]
- pre_get_posts causes Custom Posts appear under ‘Pages’ menu
- Assign a tag to custom post type using a query
- Categorizing Custom Posts in Bulk Based on Title