4

I've created a custom post type called 'events'. I've also created a custom taxonomy called 'event_categories' containing the 12 months of the year.

I am trying to get 'events' held in August AND (not OR) September (term IDs 41 and 42) using the following urls:

/wp-json/wp/v2/events?event_categories=41,42

/wp-json/wp/v2/events?event_categories=41+42

For some reason these urls return the same results and don't use the AND operator. They both use the OR operator and return events that are in either August or September.

I've also tried the following urls below but neither utilise the AND operator:

/wp-json/wp/v2/events?filter[event_categories]=august,september

/wp-json/wp/v2/events?filter[event_categories]=august+september

  • Thanks Inarilo, but I've already tried that guide and for some reason it doesn't fix the issue. – Louis S Aug 21 '17 at 21:23
  • please post the code you are using based on that guide – inarilo Aug 22 '17 at 6:49
  • appears to be a problem with WP wordpress.org/support/topic/… rest_query_vars, has been removed. one of the commenters added their solution. – inarilo Aug 22 '17 at 21:41
  • Thanks for looking into this inarilo! I followed some of the suggestions in the comments but it didn't make a difference. Their main problem at the time was that filter[event_categories] wasn't working at all. It's working for me but it's just not using the AND operator with multiple taxonomy values separated by ','. It could still be an issue with rest_query_vars but I can't figure out what it is. – Louis S Aug 22 '17 at 22:14
1

I think I know the fix. I noticed that the plus sign (+) in the url arguments was automatically being stripped and converted into a space.

My arg values 'august+september' were becoming 'august september' after decoding. I found out that '%2B' is the code equivalent of the + symbol.

So, instead of using: /wp-json/wp/v2/events?filter[event_categories]=august+september

Use: /wp-json/wp/v2/events?filter[event_categories]=august%2Bseptember

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.