Mik*_*ike 0 ajax wordpress jquery
我有这个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>
Run Code Online (Sandbox Code Playgroud)
我有一个名为addpost.php的文件,它位于WP的根安装文件夹中的actions文件夹中.
<?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 );
?>
Run Code Online (Sandbox Code Playgroud)
问题是休息:如果我删除require('../wp-blog-header.php');我没有收到任何错误,否则我在控制台中收到此错误:
POST http://localhost/wp-content/themes/sometheme/actions/addpost.php 404 (Not Found)
Run Code Online (Sandbox Code Playgroud)
但是我需要wp-blog-header.php才能进行帖子插入.
更新: addpost.php中的脚本被执行但发送答案时出现错误.
有任何想法吗?
| 归档时间: |
|
| 查看次数: |
1416 次 |
| 最近记录: |