// Create post object
$my_post = array();
$my_post['post_title'] = 'My post';
$my_post['post_content'] = 'This is my post.';
$my_post['post_status'] = 'publish';
$my_post['post_author'] = 1;
$my_post['post_category'] = array(0);
// Insert the post into the database
wp_insert_post( $my_post );"
This works fine. You code is correct, but it is an problem in the form to send the $_POST data?
See on this post for feature informations
Related Posts:
- delete post also attachments
- Enabling Sessions in WordPress 3.0
- How to let a single post have its own domain name
- Retrieving and Storing Images Linked from Other Domains on Local Server?
- Allow role to delete posts but block him the wp-admin
- Why does `url_to_postid` return 0 when testing `page_for_posts` Page?
- Best way to pass arguments to another page in WordPress
- Delete Post From Front-End and attachment permanently
- WP_Query with the “offset” argument
- WordPress change author email notify message?
- Set user loggin status?
- Stopping People Viewing Draft Posts
- Run a function when post is deleted?
- How to remove tag cloud from taxonomy admin edit page?
- Access post meta in future_to_publish function
- Author Tracking Code!
- Allow users to create posts without logging in?
- Redirect to another page using contact form 7? [closed]
- disable Tab post on nav-menus page (Admin)
- Format latest/newest post differently
- I want to print a message in post ” After one month from publish date”
- WordPress : using AJAX to get posts & Sidebar Content to an external application
- Specific colours for wordpress author ids
- Optimize CPT-function with a loop
- Problem with custom function from jQuery slider tutorial
- Help on conditional statement to accompany wp_insert_post function please?
- Different profile page by role
- Troubles about insering a POST with a SQL query, post_status
- Add array of post id’s to a category?
- How to put the author of the post in the comments?
- Alt text attributes not showing over portfolio images
- How to add a custom class attribute into code wrapper? [duplicate]
- Add multiple HTML attributes to an Elementor button
- Is it possible to change the attributes of a registered style or script before it fires?
- how to change “published date” format on edit.php (Posts page)?
- How to change submit button value in comment from “Post Comment” to “Send”
- Code to auto expire posts after 30 days
- Create subpage /user/ or /my-profile/ like /author/ with additional query like /user/user123
- How to change in customizer the “site identity” tab required capabilities
- How to hide WordPress files / structure? [closed]
- Custom function for user register in wp?
- Customizer: How do you add HTML to control labels?
- Customizing the default logout page of WordPress
- multiple comment text areas
- How to show in search results posts with a particular tag in a particular category?
- Create cron job without a plugin?
- show the meta values to visitors that collected via coment form
- Custom URL going to 404
- TinyMCE custom dialog with selectbox not working
- Load more posts with multiple queries
- Find resources dynamically loading and change or add to the url
- How to wrap the list with custom class using wp_nav_menu?
- Custom search to display results within same page
- Get ORIGINAL image links from get_post_gallery
- change url for static files in /wp-admin with a cdn url
- Sub menu indicator that links to sub menu
- How can I have a common background color across multiple WordPress blocks?
- Get Custom Taxonomy Terms by Date
- What exactly do this function declared into functions.php file of a WP theme?
- Removing blank space below header [closed]
- Is it possible to customize the post according to post format in single.php?
- Post type no single page
- Why There Is No “get content by ID” Function
- Archive subtitles for different types of archives
- Point homepage to custom php page
- Randomizing wp_tag_cloud() in child theme
- Replace plugin function with a custom function?
- How can I tag a menu item as visited for each unique user?
- Querying another post category to match current post and display in loop
- Add Member’s birthdate from Backend and shows it on frontside [closed]
- Many Rewrite Parameters/Rules
- Query function not executed between element [closed]
- How to Render Post Types in RSS Feed?
- 404 when Previewing an unsaved draft
- Custom Taxonomy Sort For a Custom Query
- How Can I Always Display A Particular Post First Using WP_Query?
- Display a specified content on a Page and all its child pages
- MySQL: Possible to replace all of wp_posts.post_content(id#) via UPDATE + REPLACE + SELECT?
- Custom field not editable by the user
- WordPress category custom title
- Use a custom page with dynamic content as a user profile page
- Add helper text in custom-header section in admin
- How to edit content in code view of home page when there is some theme applied?
- How to display strikethrough text in button text (for special offer)
- Remove Title and White Space in Twenty Twenty theme
- Add a custom intro page
- How to have differents sites share the same tables of DB?
- How to change custom link of subpages from of localhost to website
- Custom login doesn’t stay
- Custom dropdown search form that allows users to select option B based from Option 1
- Smarter Document Management links between three WordPress sites sought
- How to make an If Else on Excerpt Filter
- WordPress get_post_meta issue
- Create a google friendly header with text and logo
- Custom Link In WordPress Media “Attachment Details” Upload Screen
- How to add button to top of theme customizer?
- How remove “recent comments” title without modifying code? [closed]
- Need to show birthday of custom post type(Famous people in this case) in elementor. Date of birth set in custom fields
- How to Add Extra Text In WordPress Title Before Post Publish
- Problem with removing characters “<” – WpAllImport