How to insert post from external php file?


I have this php file on the root directory, and i seen this example for inserting post from external php file
but for some reason it doesn’t work for me, wp_insert_post() always returns 0

So whats the problem ? and how i can fix it?

I’m trying to build a Cron Job file to insert new posts from XML file In the end

Thank you!



require_once  './wp-load.php';

$new_post = array(
    'post_title' => 'My New Post',
    'post_content' => 'Lorem ipsum dolor sit amet...',
    'post_status' => 'publish',
    'post_date' => date('Y-m-d H:i:s'),
    'post_author' => '3',
    'post_type' => 'post'
$post_id = wp_insert_post($new_post);

var_dump($post_id); die; // Return  int(0)
, Moti Winkler 5 years 2017-01-20T05:52:56-05:00 0 Answers 105 views 0

Leave an answer