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 disable PHP warnings in WordPress?
- How to send an email using PHP in WordPress?
- How to get the current URL in WordPress using PHP?
- How to add a shortcode in WordPress?
- How to use get_header in WordPress using PHP?
- How to check the PHP version in WordPress?
- How to create a menu in WordPress using PHP?
- How to increase the upload limit in WordPress using PHP?
- How to redirect to another page in WordPress using PHP?
- How to create a snippet in WordPress using PHP?
See more codes...