The insert post works correctly, but then afterwards get a 500 internal server error for some reason, tested on a simple localhost site on my computer but error does not occur. :-

global $user_ID;

$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' => $user_ID,
    'post_type' => 'post',
    'post_category' => array(0)

$post_id = wp_insert_post($new_post);
  • have you try with default theme et all plugins desactivated ? – mmm Apr 29 '17 at 21:05
  • Yes deactivated all plugins, but still occurs. using 2017 theme. – user1199360 Apr 29 '17 at 23:35
  • 2
    a 500 error indicates something went wrong and to look at the error log, you should follow the usual debug process of checking PHP error logs for fatal errors and warnings, and turn on WP_DEBUG – Tom J Nowell Apr 30 '17 at 2:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.