这个想法很简单。我有一个用get\\u categories()生成的下拉菜单。这将输出无序列表中的类别列表,每个类别都位于其自己的li元素中
当用户单击这些li元素时,我会得到它们的文本值,并基于此,我想创建一个自定义wp\\U查询,该查询只返回该类别中的帖子。为此,我将list元素的文本值加载到JS变量中,并将其发送到php文件进行处理。该php文件按如下方式构造字符串:
$ff_query = new WP_Query(\'posts_per_page=2&category_name=\'.$_POST[\'JSvariable\']);
…理想情况下应该执行它,从DB返回信息。我得到的错误是:“致命错误:C:\\xampp\\htdocs\\suply\\WP content\\themes\\suply\\includes\\proc\\u cat.php中未找到类‘WP\\u Query’”第3行”
这是我的2个文件的外观:
1) 发送ajax请求的文件:
<script>
$(document).ready(function(e) {
$("#ddmenu li").on(\'click\', function() {
var cValue = $(this).text();
$.post("<?php bloginfo(\'template_url\');?>/includes/proc_cat.php", {name: cValue}, function(cat){
alert(cat);
$(".browse-big-slider").append(cat);
});//end of post
});//end of click
});//end of ready
</script>
2)应处理if(isset($_POST)){
$name = \'posts_per_page=2&category_name=\'.$_POST[\'name\'];
$ff_query = new WP_Query(\'posts_per_page=2&category_name=\'.$_POST[\'name\']);
something else, but it won`t reach this part.
}
我能做些什么来实现这一目标?或者,作为替代方案,我如何创建我想要的功能类型?(基本上是根据用户选择动态生成的不同查询)。