When you use wp_insert_post to create the post, it will return the post id of the post you just created. The following code demonstrate how to add meta values:
$my_post_data = array(
'post_title' => $collection,
'post_type' => 'post',
'post_content' => '<p style="margin-bottom: 10px;">' . $content . '</p>',
'post_category' => array(
$term->term_id
),
'post_author' => 1,
'post_status' => 'publish',
'post_date' => date('Y-m-d H:i:s')
);
$post_id = wp_insert_post( $my_post_data );
if ( ! $post_id && ! is_wp_error( $post_id ) ) {
add_post_meta( $post_id, 'title', 'This is a title' );
add_post_meta( $post_id, 'description', 'This is a description' );
}
Related Posts:
- Redesigning Custom Post Type “Add New” page
- Can we hook a static method of a class to add_action inside that class?
- Is there any record of installed plugins in the database?
- Being notified when some YouTube video in some post becomes unavailable
- Custom headers for the WordPress plugin directory
- Is it possible to run plugin code when a multisite blog is deleted?
- plugin wants to update to wrong plugin
- How can I add a custom header to a custom template in a plugin without using the theme folders
- Trying to avoid including wp-load.php
- Stackoverflow type of badge plugin giving warnings in WordPress 3.5
- AJAX Call Via Vanilla JavaScript In WordPress Plugin Development
- How to add terms to a post depending on its title?
- What Triggers a Plugin Update Alert
- Make the plugin directory recognize new version numbers
- How to include admin-ajax when loading external javascript
- WooCommerce Dynamic Cart Pricing
- Remove action from a plugin class, forced to use global instance
- How to get last_updated and newest_blogs in WP 3.0
- WP Mail SMTP: What do the SSL/TLS options mean? [closed]
- How to make first_name and last_name required fields in user profile?
- Security issues with WP sites
- Avoiding Duplicate function names in Post Loop (WP_Footer script)
- How to add page using HTML, CSS and JS?
- Can we use a webservice with WordPress?
- WooCommerce get_price returning wrong price when used via ajax
- How I can get custom field’s current value?
- Want wp_get_post_terms return in arbitrarily order, how to do?
- How to resize images due to container width automatically server side/without CSS
- Checking instances of scripts in wp_head
- How to access data in wordpress database externally using php
- Add javascript to wp_head with call to plugin options?
- How to redirect a URL with parameters?
- How to create a managed image repository in wordpress
- Anonymous Postings
- how to add a button next to the wordpress view button?
- How can I prevent my plugin go development trunk [closed]
- (FES EDD) New vendor submission page is blank
- Are functions in main plugin file called before function bound to register_activation_hook runs?
- After plugin activation all users marked as Spam
- How to create a code editor for my plugin .?
- Manually set a custom admin sub-menu selected?
- Fatal error can’t activate a plugin [closed]
- Edit External CSS
- How to pass variables to a function argument using add_action [duplicate]
- Identifying where plugins are being used in your wordpress install
- How to get the particular product quantity in orders in Woocommerce [closed]
- Tutor LMS problem with Paid Memberships Pro [closed]
- Best way to salvage a very old WP site
- Development of plugins to add components like JqueryUI
- Update WP option by plugin
- plugin enqueue style on all pages
- File Uploader – Upload without adding to Media Library
- why the wp_register_script doesn’t work for register_activation_hook
- Trying to include files in plugin isn’t working
- Table appears in Visual mode of editor but not in preview or after publish
- Pull comments from one page/post into another page/post?
- Do WordPress plugins suport multisite site?
- What’s the default setting for including a in a post
- Any gallery plugins that allow commenting on single images?
- How To Use do_shortcode with WooCommerce One Page Checkout
- Displaying page content from plugin, inside exising empty WP page
- GitHub plugins safe to use in my website?
- implement custom roles in custom plugin
- Update widget values from ajax function
- implement checkbox or toggle switch in plugin code
- how can export data in excel file custom plugin
- dbDelta not CREATING TABLE
- wp_mail in pluggable.php return path original settings
- wordpress form not saving or updating
- woocommerce with external ftp site
- How to put a maximum real-time users limit
- How to exclude a part of a page in search results
- Seeking specific WordPress Layout
- Help finding a plugin – masonry type post grid
- WP_CRON issue with UTC and local time
- Custom admin plugin read CSV
- Multiple Meta key in search
- How can I call functions from a custom plugin?
- How to get short description under heading – Visual Composer [closed]
- plugin installing error
- Get custom term link archive with prefix
- Why the output of an image gallery plugin is not displayed into a page of my custom theme?
- Plugin, add opengraph tags after form submit
- How to save information related to post in database?
- Filter html of WordPress editor in visual mode only
- Creating a page that does not show up in the frontend navigation bar
- Multiple Plugins Interacting with Menu
- Plugin constructor called multiple times
- how to call jQuery in admin as well as in homepage
- How to programmatically detect how many posts are displayed per page?
- wordpress last all added get meta value by post id
- Is a custom post type considred a plugin?
- Migrate DB Plugin: Error “The directory needs to be writable”
- WP Offload S3 Lite “Please setup GD or ImageMagick” noticed
- Woocommerce disable checkout on specific day
- How to delete Password Protected posts cookies when a user logged out from the site
- wp_options Table keeps growing
- Run a function only once when logging into dashboard
- How to call a logging function from a generic utility plugin from another plguin
- WordPress – How to add an attribute to a plugin inline script tag