查询字符串过滤

时间:2021-07-28 12:40:45

标签: javascript jquery wordpress query-string wordpress-rest-api

目前,我正在开发一个搜索应用程序,该应用程序根据商店特征(自定义分类)ID 搜索/过滤商店(自定义帖子类型)。当我使用 WordPress Fetch API 时,我可以毫无问题地获取完整的自定义帖子类型数据。问题是我一直在尝试构建的查询字符串。我本质上是在尝试通过 AND 而不是 OR 来过滤查询字符串。

示例:

  • Store One 商店功能:55 和 96
  • 商店两个商店功能:55
  • 店铺三大店铺特色:96

查询字符串只需要返回 Store One,因为它包含两个 ID(AND)。它不能仅仅因为它包含这些 ID(或)中的任何一个就返回存储二或存储三。以下是我迄今为止尝试过的一些示例。

http://localhost/my-site-name/wp-json/wp/v2/locations/?store-features=55&store-features=96

http://localhost/my-site-name/wp-json/wp/v2/locations/?store-features=55+96

注意:查询字符串由前端的 50 个复选框构建,对应于 store-features。

[{
    "id": 1,
    "name": store 1,
    "store-features": [
        55,
        53,
        61,
        64,
        66,
        68,
        73,
        74,
        79,
        80,
        81,
        85,
        87,
        88,
        89,
        90,
        91,
        92,
        93,
        96,
        98
    ]
}, {
    "id": 2,
    "name": store 2,
    "store-features": [
        54,
        55,
        53,
        63,
        64,
        66,
        68,
        73,
        74,
        76,
        79,
        81,
        84,
        85,
        87,
        88,
        89,
        90,
        91,
        92,
        93,
        98
    ],
}, {
    "id": 3,
    "name": store 3,
    "store-features": [
        53,
        61,
        64,
        66,
        68,
        73,
        74,
        79,
        80,
        81,
        85,
        87,
        88,
        89,
        90,
        91,
        92,
        93,
        96,
        98
    ]
}]

谢谢, 肖恩

0 个答案:

没有答案