Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/236.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用自定义分类法筛选Wordpress帖子_Php_Jquery_Ajax_Wordpress - Fatal编程技术网

Php 使用自定义分类法筛选Wordpress帖子

Php 使用自定义分类法筛选Wordpress帖子,php,jquery,ajax,wordpress,Php,Jquery,Ajax,Wordpress,我有我的Wordpress博客文章的自定义分类法。我希望允许用户使用AJAX过滤它们。我已经能够调用整个页面并以这种方式获得结果,但我的响应包括所有HTML。我想知道是否有办法通过AJAX过滤Wordpress帖子并返回结果对象 这就是我目前拥有的: jQuery.ajax({ type: "POST", data: "&product_form="+product_form, url: "http:

我有我的Wordpress博客文章的自定义分类法。我希望允许用户使用AJAX过滤它们。我已经能够调用整个页面并以这种方式获得结果,但我的响应包括所有HTML。我想知道是否有办法通过AJAX过滤Wordpress帖子并返回结果对象

这就是我目前拥有的:

        jQuery.ajax({
            type: "POST",
            data: "&product_form="+product_form,
            url: "http://localhost/websites/test/products/?filer=true",
            success: function(results) {
                console.log(results);
            }
        });

最简单的方法是在products/?filer=true中的帖子输出前后添加一些注释标记,然后根据这些标记分割结果数据

比如你把

<!--SPLITMARK-->

在POST输出之前和之后,使用js中的结果进行拆分:

    jQuery.ajax({
        type: "POST",
        data: "&product_form="+product_form,
        url: "http://localhost/websites/test/products/?filer=true",
        success: function(results) {
            results = results.split("<!--SPLITMARK-->");
            results = results[1];
            console.log(results);
        }
    });
jQuery.ajax({
类型:“POST”,
数据:“&product_form=“+product_form,
url:“http://localhost/websites/test/products/?filer=true",
成功:功能(结果){
结果=结果。拆分(“”);
结果=结果[1];
控制台日志(结果);
}
});
无论如何,这种方法是快速的方法,但有点脏