You can use the wp_insert_post
function
$my_post = array(
'post_title' => 'Some titles',
'post_content' => 'This is my post content',
'post_status' => 'publish',
'post_author' => 1,
'post_category' => array(1, 2, 9000)
);
// Insert the post into the database
wp_insert_post( $my_post );
}
Related Posts:
- Add custom Attachment Display Setting for images
- Rewriting post slug before post save
- Removing filter dropdown in posts table (in this case Yoast SEO)
- Getting the post_id in wp_ajax function
- How to know if get_posts() failed?
- Show related posts by category but ignore one category
- Replacing all attachment links in post with media file link
- Change the default number of posts to show on mobile version
- Post content being duplicated by the_content();
- How can I pass $post object to ‘save_post’ add_action?
- Disable REST API for a user ROLE
- Insert posts in two tables
- How To Keep Posts from Being Displayed Two or More Times on My Homepage? [closed]
- custom wordpress post loop – hide iframe content
- Different template for posts of all subcategories of category
- Add custom field automatically (add_post_meta) with value based on number of words of article
- How to access featured image?
- Mark menu item as current-menu-item for category
- previewing my posts on static page?
- How to retrieve the postID in a “image_send_to_editor” hook function?
- Post revisions disappeared (for some posts)
- Replace ‘published on date’ with ‘modified on date’ on Posts
- How to display category from recent posts?
- Best way to assign post position in a news site homepage? (no categories, no sticky posts)
- How do I restart my loop with get_next_post()?
- “Duplicate” Posts Appearing Since 3.1.2 Update
- Rename “post” to “article” throughout the admin back end [duplicate]
- Set size for attachments
- Setup a custom dynamic post
- How to render arbitrary post without displaying it [closed]
- Adding an image to a non existing post
- How to create new post content templates for my users?
- Start post pagination at 0 instead of 1
- Excluding posts not working
- How to include my own css in post
- Find the Post ID of a post from another website
- (solved) getting post author’s user role
- Block editors annoying warnings
- Add get_the_tags() to Single Posts section via functions.php
- Disable auto-save and post revisions from inside a theme or plugin
- Inner join overrides Advanced Custom Fields plugin’s get_field [closed]
- Refresh problem post is duplicated when page is submitted after page reload
- Migrate posts from category and sub-category via SQL
- Force fill all fields when creating a new post
- register_post_type permalink
- Display recent posts from portfolio
- How to get post with slug and exclude categories
- How can I set a maximum allowed post size and number of posts submitted?
- Adding post date will not insert new post
- How to make related post order by random?
- Accessing Post ID Within Loop
- Retrieving posts by their date and category
- WordPress displays post on subcategory only
- Update field in database for users
- Short link to read complete post
- Delete all Tag Links from Posts
- Adjust the order for returned posts
- Post in bulk based on category template
- Automatic duplicate/copy of post to a related page in WordPress
- user_has_cap filter allows “edit_others_posts” but not is not allowing updating/publishing
- Change Old WordPress Post Date Year
- WordPress doesn’t save or publish new posts
- Yoast breadcrumb URL shows category instead of the page
- Add data attribute of post_id for Internal links
- Menu Items disappearing/being empty on save or post edit
- Display/Filter post using if else statement
- Private post caught in endless redirect loop
- Foreach issue in get_posts function
- Contributor edits published post and sends for review – post is made private?
- Why does my “Add New Post” page have an old post in it?
- link to edit a post has empty target
- Nestling Posts Under Page & Justify Text
- Redirect to custom post if custom archive page has just one result?
- Adding posts updates previous post
- Strange behaviour in WordPress admin
- How do you update post date (year only) in a separate custom field?
- Is it possible to make a custom post that adds multiple pages?
- Creating a link to the first post in a category
- sometimes on saving a post as draft, it says Access Denied You don’t have permission to access “mywebsite.com/wp-admin/post.php”
- How do I change the post title’s link on the posts page?
- How do I make it so that new posts within a certain category go into a certain page?
- WordPress text field in array problem
- List Authors For Current Category
- Get query result according to merged array
- cleaning out posts that don’t exist anymore but links are still there
- Custom URL Structure for posts with subcategories
- Possible to display X number of authors posts from another WordPress site?
- Theme Unit testing not importing on MAMP server – Fatal error: Maximum execution time of 60 seconds exceeded
- Assign specific ads to specific categories/posts
- Reading Setting Not Working for Number of Posts
- 404 for some custom taxonomy not ALL taxonomy
- Add tags to post before it’s created
- can’t post immediately
- List posts that are in the same category as the current post title
- save_post not working
- Password-protected Posts lead to 404 Error
- Multiple blog “feeds” in a single blog each with distinctly styled post pages
- How to get pagination working with “Pending” Posts
- Post’s arent displaying
- Show with echo if a post has two or more categories