Question

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

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top