WordPress.org

Make WordPress Core

Opened 3 weeks ago

Last modified 3 weeks ago

#44326 new enhancement

Add relation parameter to REST API /wp/v2/posts endpoint

Reported by: earnjam Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.7
Component: REST API Keywords: has-patch has-unit-tests
Focuses: rest-api Cc:

Description

The REST API /wp/v2/posts endpoint allows filtering by terms across multiple taxonomies, but it always uses an AND relationship between them.

Basically: /wp/v2/posts?tags=1&categories=2

Translates to: All posts with Tag 1 AND Category 2

WP_Query supports passing a relation parameter when running a tax query across multiple taxonomies. It defaults to AND, which is what we do now, but it would be nice to support the ability to specify OR here as well.

Attachments (1)

44326.diff (5.8 KB) - added by earnjam 3 weeks ago.

Download all attachments as: .zip

Change History (2)

@earnjam
3 weeks ago

#1 @earnjam
3 weeks ago

44326.diff:

  • Adds a new parameter to the /wp/v2/posts endpoint called relation which accepts AND or OR. If left off, it defaults to the current functionality of AND.
  • Adds 2 new tests
Note: See TracTickets for help on using tickets.