如何包含wp-blog-header.php更改文件位置?

我有这个javascript:

 $('.publish_post').click (function(){ var info = 'some info'; $.ajax({ type: "POST", url: "../actions/addpost.php", data: info, success: function(data){ console.log(data); } }); })  

我有一个名为addpost.php的文件,它位于WP的根安装文件夹中的actions文件夹中。

  'closed', 'ping_status' => 'closed' , 'post_category' => 1, 'post_content' => 'some content', 'post_name' => 'some post', 'post_status' => 'publish', 'post_title' => 'some post', 'post_type' => 'post' ); $the_post_id = wp_insert_post( $post, $wp_error ); ?> 

问题是rest:如果我删除require('../wp-blog-header.php'); 我没有收到任何错误,否则我在控制台中收到此错误:

 POST http://localhost/wp-content/themes/sometheme/actions/addpost.php 404 (Not Found) 

但是我需要wp-blog-header.php才能进行post插入。

更新: addpost.php中的脚本被执行但发送答案时出现错误。

有任何想法吗?

将wp-blog-header.php包含在非wordpress页面中并不是一种好习惯。 这就是您收到404错误的原因。

你应该尝试包括wp-load.php。