// 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 add a ribbon in the background of h1 on every page?
- Add a date updated/date modified option using custom fields
- Move first half of posts to one parent page, second half to the other page
- wp_trim_words() does not work with my code Am I doing any mistake in my code?
- custom theme ,add media not showing images in media library
- woocommerce_checkout_fields modifying existing billing_phone label created new field
- Get Image from Media Library with the Title
- IF Statement on Button to make it complete and “uncomplete” based on user action / click
- Gravity Forms Button Text
- How to add textarea field to taxonomy (tag)?
- Adding buttons to Add New Post and Add New Page
- How to pick the default selected value in wordpress dropdown?
- Get Custom Logo Alt Text
- Resizing of a header/div in a website through css in wordpress [closed]
- Contact From 7 Custom Validation Issues
- How to add an extra button on woocommerce shop page and use it to send the product info with image in a mail? [closed]
- Gutenberg block outputting JSON in front end – is this normal?
- Find resources dynamically loading and change or add to the url
- How to change the category url jusy show /category/%category_id% in wordpress?
- Custom Post Type – Category Rewrite – Remove Rewrite from Sitemap
- Change the Labels of Users to Customers in Admin
- how do I remove the shipping from woocommerce thankyou page and from the email
- Load MediaPlayerElement after Infinity Scroll loads more posts
- Custom post type adds time/date and author to the post?
- How would you implement a CTA infront of a videoplayer? [closed]
- Get Date of custom field and use conditional logic
- Show titles, date of all posts on single category page
- Control Content On Non-Blog Pages
- need help with a user-specific custom page template
- How can I use a Tiny MCE editor in my custom Gutenberg block?
- Always logged in even if remember me is unchecked?
- Add custom profile field only for site admins?
- Adding posts to custom menu [closed]
- CPT archive redirects to single post
- How to display the link (title) and thumbnail post?
- Woocomerce custom billing address fields display in order details [closed]
- How to add an extra variable to login and authenticate it?
- Bind JS event to WordPress control customizer
- Color swatches on category page? [closed]
- Show posts by a custom post author
- Steps for custom data retrieval
- changing font size and font of a custom message added after comment
- Edit sticky header html – How to locate corresponding php file
- Include custom JS without child theme
- help to change some colors (woocomerce and store locator) [closed]
- Remove add news page and posts from menu
- Force the “Choose from the most used tags” meta box section to always be expanded
- Show the content that is after the excerpt using child theme
- Custom Status of Custom Post type need to EXCLUDE from Taxonomy pages
- Show Featured Post Only On The Homepage
- Prepopulating a specific page template with HTML/CSS
- When sale price is 0.00 show only regular price
- The function can not create a table on MariaDB server
- Child theme .css files are not overriding their parent .css files
- redirect post id to post full url
- Allow a Widget to be used one time only?
- Custom loop pagination links not working
- One WordPress Installation for 2 Domains
- custom meta box for page default template
- Prevent Delete Attachment by URL or When Submit
- result from custom filter admin table list backend does not work
- How can I create a second multisite network in a subdirectory?
- Silo Structure; Will links from home page to a Sub-category or Post undermine silo seo advantage? [closed]
- How to allow users to post only in certain category and hide elements from edit page?
- Update postmeta Parent when post_status child change
- Calling an attribute from a plugin shortcode
- Enable Comments Box On Custom Post Type