包括wp-blog-header.php如何更改文件位置? [英] how does including wp-blog-header.php change the file location?
问题描述
我有这个javascript:
I have this javascript:
<script type="text/javascript">
$('.publish_post').click (function(){
var info = 'some info';
$.ajax({
type: "POST",
url: "../actions/addpost.php",
data: info,
success: function(data){
console.log(data);
}
});
})
</script>
我有一个名为addpost.php的文件,该文件位于WP的根安装文件夹中的actions文件夹中.
I have this file called addpost.php that is located in actions folder that is in the root install folder of WP.
<?php
require('../wp-blog-header.php');
$post = array(
'comment_status' => '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 );
?>
问题在于休憩:如果删除require('../wp-blog-header.php');
,我不会收到任何错误,否则会在控制台中收到此错误:
The problem is the fallowing: if I delete require('../wp-blog-header.php');
I receive no error, otherwise I receive this error in the console:
POST http://localhost/wp-content/themes/sometheme/actions/addpost.php 404 (Not Found)
但是我需要wp-blog-header.php才能插入帖子.
However I need wp-blog-header.php in order to make the post insert.
更新:addpost.php中的脚本已执行,但发送答案时出现错误.
UPDATE: The script in addpost.php gets executed but the error appears when the answer is sent.
有什么想法吗?
推荐答案
将wp-blog-header.php包含在非WordPress页面中不是一种好习惯.这就是为什么出现404错误的原因.
It is not good practice to include the wp-blog-header.php into non-wordpress pages. This is why you are getting the 404 error.
您应该尝试包括wp-load.php.
You should try including wp-load.php.
这篇关于包括wp-blog-header.php如何更改文件位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!