Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Terms: Respect order specified by register_taxonomy() #67154

Merged
merged 5 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions backport-changelog/6.8/7848.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
https://github.com/WordPress/wordpress-develop/pull/7848

* https://github.com/WordPress/gutenberg/pull/67154
23 changes: 23 additions & 0 deletions lib/compat/wordpress-6.8/rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,26 @@ function gutenberg_add_post_type_rendering_mode() {
}
}
add_action( 'rest_api_init', 'gutenberg_add_post_type_rendering_mode' );

// When querying terms for a given taxonomy in the REST API, respect the default
// query arguments set for that taxonomy upon registration.
function gutenberg_respect_taxonomy_default_args_in_rest_api( $args ) {
// If a `post` argument is provided, the Terms controller will use
// `wp_get_object_terms`, which respects the default query arguments,
// so we don't need to do anything.
if ( ! empty( $args['post'] ) ) {
return $args;
}

$t = get_taxonomy( $args['taxonomy'] );
if ( isset( $t->args ) && is_array( $t->args ) ) {
$args = array_merge( $args, $t->args );
}
return $args;
}
add_action(
'registered_taxonomy',
function ( $taxonomy ) {
add_filter( "rest_{$taxonomy}_query", 'gutenberg_respect_taxonomy_default_args_in_rest_api' );
}
);
ockham marked this conversation as resolved.
Show resolved Hide resolved
Loading