【问题标题】:Filter through Wordpress posts with Custom Taxonomies使用自定义分类法过滤 Wordpress 帖子
【发布时间】:2015-12-09 18:45:19
【问题描述】:

我的 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);
            }
        });

【问题讨论】:

    标签: php jquery ajax wordpress


    【解决方案1】:

    最简单的方法是在 products/?filer=true 中的帖子输出之前和之后放置一些评论标记,然后根据这些标记拆分结果数据。

    比如你放

    <!--SPLITMARK-->
    

    在帖子输出之前和之后,然后在 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);
            }
        });
    

    无论如何,这种方法是快速的方法,但有点脏......

    【讨论】:

      猜你喜欢
      • 2020-11-17
      • 1970-01-01
      • 1970-01-01
      • 2017-12-21
      • 1970-01-01
      • 2023-04-10
      • 1970-01-01
      • 1970-01-01
      • 2016-11-21
      相关资源
      最近更新 更多