title: When Programmatically Creating a Post in WordPress, must the Executable php File with wp_insert_post be Located in the wp-includes Folder?
body: <p>I ask this question with the following context:</p>
  
  <p>I want to programmatically create a post in Wordpress using wp_insert_post().</p>
  
  <p>I originally saved the executable php file in the wp-includes folder, but I could not run the php file from my browser, which I wanted to do for convenience. </p>
  
  <p>I saved the executable php file at /public_html/folder/executable_file.php and ran this code from the Chrome browser:</p>
  
  <pre><code>&lt;?php
      $postContent = 'test post';
      $title = 'test title';
  
      // Create post object
      $my_post = array(
          'post_title'    =&gt; $title,
          'post_content'  =&gt; $postContent,
          'post_status'   =&gt; 'publish',
          'post_author'   =&gt; 1,
          'post_category' =&gt; 'uncategorized'
      );
  
      // Insert the post into the database
      wp_insert_post( $my_post );
  
      echo 'At least the file executed :/';
  ?&gt;
  </code></pre>
  
  <p>The browser returned</p>
  
  <p>"This page isn’t working</p>
  
  <p>website.com is currently unable to handle this request.
  HTTP ERROR 500"</p>
  
  <p>I have tried several variations of the above code with different errors. I suspect these errors occur because the code is run from another folder, because codex , because even though Wordpress Documentation does not explicitly say it, the post.php example is located in wp-includes. 
  (<a href="https://developer.wordpress.org/reference/functions/wp_insert_post/" rel="nofollow noreferrer">https://developer.wordpress.org/reference/functions/wp_insert_post/</a>)</p>
  
  <p>tl,dr; 
  Can wp_insert_post be run from outside of the wp-includes folder?</p>
  
  <p>Thank you for saving time by providing this answer.</p>