REST API: Add tax relation parameter to posts collection.

The REST API supports filtering by terms across multiple taxonomies using an AND relation. This adds support for an OR relation by adding "tax_relation=OR" as a query parameter.

Props earnjam.
Fixes #44326.

Built from https://develop.svn.wordpress.org/trunk@46646


git-svn-id: http://core.svn.wordpress.org/trunk@46446 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
TimothyBlynJacobs 2019-11-03 23:14:02 +00:00
parent a4687f9134
commit 5124c542e1
2 changed files with 13 additions and 1 deletions

View File

@ -270,6 +270,10 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
$taxonomies = wp_list_filter( get_object_taxonomies( $this->post_type, 'objects' ), array( 'show_in_rest' => true ) );
if ( ! empty( $request['tax_relation'] ) ) {
$query_args['tax_query'] = array( 'relation' => $request['tax_relation'] );
}
foreach ( $taxonomies as $taxonomy ) {
$base = ! empty( $taxonomy->rest_base ) ? $taxonomy->rest_base : $taxonomy->name;
$tax_exclude = $base . '_exclude';
@ -2531,6 +2535,14 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
$taxonomies = wp_list_filter( get_object_taxonomies( $this->post_type, 'objects' ), array( 'show_in_rest' => true ) );
if ( ! empty( $taxonomies ) ) {
$query_params['tax_relation'] = array(
'description' => __( 'Limit result set based on relationship between multiple taxonomies.' ),
'type' => 'string',
'enum' => array( 'AND', 'OR' ),
);
}
foreach ( $taxonomies as $taxonomy ) {
$base = ! empty( $taxonomy->rest_base ) ? $taxonomy->rest_base : $taxonomy->name;

View File

@ -13,7 +13,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.4-alpha-46645';
$wp_version = '5.4-alpha-46646';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.