简体   繁体   English

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

[英]Filter through Wordpress posts with Custom Taxonomies

I have custom taxonomies for my Wordpress blog posts. 我的Wordpress博客文章有自定义分类法。 I would like to allow users to filter through them using AJAX. 我想允许用户使用AJAX对它们进行过滤。 I've been able to call the full page and get the results that way, but my response includes all the HTML. 我已经能够调用整个页面并以这种方式获得结果,但是我的回答包括所有HTML。 I'm wondering if there is a way to filter through Wordpress posts via AJAX and get the resulting object returned? 我想知道是否有一种方法可以通过AJAX筛选Wordpress帖子并返回结果对象?

This is currently what I have: 这是我目前拥有的:

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

Easiest way is to put some comment marks just before and after output of your posts in products/?filer=true and then split the resulting data based on this marks. 最简单的方法是在product /?filer = true中,在帖子输出的前后放置一些注释标记,然后根据该标记分割结果数据。

For example you put 例如你放

<!--SPLITMARK-->

right before and after posts output, then you do the splitting with result in js: 在发布输出之前和之后,然后在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);
        }
    });

Anyway that method is fast approach but kinda dirty... 无论如何,这种方法是快速的方法,但有点脏...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM