## How to insert post from external php file?

Question

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!

CronJob.php:

<?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)