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:
@@ -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;
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user