Hi, yeah I wanted to do pretty much the same thing and I had pretty much the same problem. Just like you I made the error to start by including files one by one waiting for the server to tell me what were the missing dependencies… Here’s how I got it solve :
1. Remove all include and require statements and replace it with this single statement :
require_once(‘yourwordpressdirectory/wp-config.php’);
this is the only file you really need to include to have a working wp_insert_post function… actually here’s a whole file you can test :
<?php
/*
Plugin Name: ImportWikiNews
Plugin URI: https://www.emuwiki.com
Description: A brief description of the plugin.
Version: The plugin’s Version Number, e.g.: 1.0
Author: Name Of The Plugin Author
Author URI: https://URI_Of_The_Plugin_Author
*/
require_once(‘yourwordpressdirectory/wp-config.php’);
function post_a_wiki_news() {
// create post object
class wm_mypost {
var $post_title;
var $post_content;
var $post_status;
var $post_author; /* author user id (optional) */
var $post_name; /* slug (optional) */
var $post_type; /* ‘page’ or ‘post’ (optional, defaults to ‘post’) */
var $comment_status; /* open or closed for commenting (optional) */
}
// initialize post object
$wm_mypost = new wm_mypost();
// fill object
$wm_mypost->post_title = rand(1,1000);
$wm_mypost->post_content = ‘test’;
$wm_mypost->post_status = ‘publish’;
$wm_mypost->post_author = 1;
$wp_rewrite->feeds = ‘no’;
// Optional; uncomment as needed
// $wm_mypost->post_type = ‘page’;
// $wm_mypost->comment_status = ‘closed’;
// feed object to wp_insert_post
wp_insert_post($wm_mypost);
}
?>
———————
This file actually works for me. the way its made now, it creates a new post with a random number between 0 and 1000, but you can modify this for whatever you need. It needs to be put in /wordpress/wp-content/plugins/ and activated in the wordpress plugin panels (*not sure that’s necessary but just to be sure). Then since it defines a function post_a_wiki_news(), you can just put another php file elsewhere on your server that would contain this :
<?php
include_once(‘yourwordpressdirectory/wp-content/plugins/testwp.php’);
post_a_wiki_news();
?>
and everytime you browse to this file on your browser, there is a new post that is created that contains a random number as a title (you will replace this with whatever you need