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 configure Nginx for WordPress?
- How to disable PHP warnings in WordPress?
- How to set a page title in WordPress using PHP?
- How to send an email using PHP in WordPress?
- How to create a WordPress plugin using PHP?
- How to create a menu in WordPress using PHP?
- How to use hooks in WordPress with an example?
- How to run an SQL query in WordPress using PHP?
- How to increase the upload limit in WordPress using PHP?
- How to get the site URL in WordPress using PHP?
See more codes...