我有Ajax调用获取响应,在响应文件中我使用了wordpress循环并获取此错误: 致命错误:班级' wp_query'没找到......
我想在Index.php中的某个div中显示一些特殊页面内容,并使用Ajax将返回结果显示到index.php
这里:
<script>
myfunc = function()
{
$("#target").slideUp(300);
$("#target").slideDown(300,"swing",function()
{
splittedURL=window.location.href.split("#");
$.post('<?php bloginfo('template_directory'); ?>/page.php','state='+splittedURL[1],function(data,status)
{
$("#target").html(data);
})
}
);
}
</script>
和这里页面:
<?php
$state=$_POST["state"];
switch ($state) {
case "2755":
echo "<b>Ok 1<b/>";
break;
case "2756":
echo "<b>Ok 2/b>";
break;
default:
?>
<!-- Page Load -->
<div id="panel-box" class="panel panel-default">
<div class="col-md-12 panel-heading">
<?php
$my_query = new WP_Query('page_id=$state');
while ($my_query->have_posts()):
$my_query->the_post();
$do_not_duplicate = $post->ID;?>
<h3 class="col-md-11 panel-title p-m"><?php the_title();?></h3>
<div class="col-md-1 close p-m" onClick="$('#panel-box').slideUp(500)">X</div>
</div>
<div class="panel-body">
<?php the_content(); ?>
</div>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
<!-- End Page Load -->
</div>
<?php
}
?>
答案 0 :(得分:3)
查找此代码:
define('WP_USE_THEMES', false);
require_once('../../../wp-load.php');
它必须在页面中定义并加载wp函数。