0

I'm trying to filter a wpapi request, using Jmespath o standard built in filter string.

I would like to retrive all "id" in the list with one or more values in the "filters" array. "Filters" is nested under "_item_filter-options".

For ex I would filter all id with "filters"==409 OR 400.

And what about filter all "id" with "locations"==217 OR other value?

Could you help me to find solution?

[
  {
    "id": 2608,
    "date": "2018-08-18T12:53:16",
    "date_gmt": "2018-08-18T10:53:16",
    "ait-locations": [
      217,
      19
    ],
    "ait_item_filters-options": {
      "filters": [
        "419",
        "400",
        "409",
        "418",
        "531",
        "403",
        "408",
        "575"
      ]
    },

  },
  {
    "id": 2588,
.....

I add some additional information, It might help to answer me. I'am using an ait-club wordpress theme with custom post type "ait-item" and meta fields.

I'm trying to use Wordpress Rest API to GET all ait-item with some properties, like latitude, title, address etc, filtered by _item_filters-options"->"filters".

Using for example http://mydomain/wp-json/wp/v2/ait-item?location=19 IT WORKS (location is a custom taxonomy). How can I retrive the same result with Jmespath?

How can get ait-item with filters=419 or more values?

Sorry for my little english, thank you.

Edit: Using:

https://www.mydomain.it/wp-json/wp/v2/ait-item?_query=[?_item_filters-options.filters[0]=='400']

i can retrive all "id" where the firt value of "filters" array is 400. I can't search in entire "filters" array!! Could you help me?

EDIT: I found solution using:

https://www.areepicnic.it/wp-json/wp/v2/ait-item?_query=[?"_ait-item_filters-options".filters[?@=='400']]

or

https://www.areepicnic.it/wp-json/wp/v2/ait-item?_query=[?"_ait-item_filters-options".filters[?contains(@,'397')]]

now I'm trying to filter with multiple values.

Tore78
  • 1
  • 3

1 Answers1

0

Filtering can be done for the filters like so, using as many or operators || as necessary to get all of the options you would like:

[?contains(_item_filters-options.filters, '409') || contains(_item_filters-options.filters, '400')].id

and similarly for locations:

[?contains(locations, '217') || ?contains(locations, '<other-value>'].id
Marcus
  • 3,216
  • 2
  • 22
  • 22
  • Could you give the complete string? I tryied but with some sintax error – Tore78 Jan 22 '19 at 00:01
  • I'm able to use it as is on jmespath.org. You may need to URL encode it before sending it to the API? – Marcus Jan 22 '19 at 18:30
  • This works: `https://www.areepicnic.it/wp-json/wp/v2/ait-item?_query=[?contains("_ait-item_filters-options".filters,'418')]` but this give me wrong result: `https://www.areepicnic.it/wp-json/wp/v2/ait-item?_query=[?contains("_ait-item_filters-options".filters,'475')]&&[contains("_ait-item_filters-options".filters,'531')]` I need to ask for items with one AND/OR more filters. – Tore78 Jan 23 '19 at 10:25