This will create a Post using PHP.
<?php
/*
Code SOURCE: https://www.youtube.com/watch?v=bVImxRBKBuc
Reference:
wp_insert_post()
*/
//set timezone
date_default_timezone_set('America/New_York');
//require native WordPress function
require_once("wp-load.php");
// Post variables
$userID = get_current_user_id();
$leadTitle='Operation Test Post'
$leadContent='Hello there. this is the post!';
//ID# automatically assigned to categories. For multiple
// categories, separate with a comma
$categoryID='28';
//Time variables - Sets time for now so post can be published without delay
$timeStamp = date_create();
$postdate = date("Y-m-d H:i:s", $timeStamp);
//wordpress Array and Variables for posting
$new_post = array(
'guid'=>$postID,
'post_title'=>$leadTitle,
'post_content'=>$leadContent,
'post_status'=>'publish',
'post_date'=>$postdate,
'post_author'=>$userID,
'post_type'=>'post',
'post_category'=>array($categoryID),
'comment_status'=>'open',
);
//THIS submits the array data to creat the new post
$post_id = wp_insert_post($new_post);
//Error Checking
if ($post_id){
echo "SUCCESS!";
} else {
echo 'OOPS! something failed, please try again!';
}
?>
872 thoughts on “Create Post Automatically”
Comments are closed.