php-wordpressHow to create a post in WordPress using PHP?
Creating a post in WordPress using PHP is a simple process. The following example code will create a post in WordPress using PHP:
$my_post = array(
'post_title' => 'My Post',
'post_content' => 'This is my post.',
'post_status' => 'publish',
'post_author' => 1
);
// Insert the post into the database
wp_insert_post( $my_post );
This code will create a post with the title "My Post" and the content "This is my post." The post will be published and the author will be the user with the ID of 1.
The code consists of the following parts:
- An array containing the post data:
$my_post
- The
wp_insert_post()
function which inserts the post into the database
For more information, please refer to the WordPress Codex.
More of Php Wordpress
- How to send an email using PHP in WordPress?
- How to disable PHP warnings in WordPress?
- How to create a snippet in WordPress using PHP?
- How to get the site URL in WordPress using PHP?
- How to add a PHP header in WordPress?
- How to configure Nginx for WordPress?
- How to hide PHP warnings in WordPress?
- How to get post meta in WordPress using PHP?
- How to get categories in WordPress using PHP?
- How to get the post ID in WordPress using PHP?
See more codes...