Make WordPress Core

Opened 2 months ago

Closed 8 weeks ago

Last modified 8 weeks ago

#62500 closed defect (bug) (fixed)

REST API: Terms controller doesn't respect taxonomy's default query args

Reported by: bernhard-reiter's profile Bernhard Reiter Owned by: bernhard-reiter's profile Bernhard Reiter
Milestone: 6.8 Priority: normal
Severity: normal Version: trunk
Component: REST API Keywords: has-patch
Focuses: Cc:

Description (last modified by Bernhard Reiter)

It is possible to supply a default set of default query args to `register_taxonomy()` which will be used when querying a list of terms -- for example, orderby in order to specify how the resulting list of terms should be sorted.

However, those default query args are not respected by the Terms REST API controller, if the request doesn't contain a post ID.

Change History (6)

#1 @Bernhard Reiter
2 months ago

The controller's get_items() method has two code branches:

  1. If a post ID is given in the network request, get_items() uses `wp_get_object_terms()` to get the terms associated with the given post. That function includes code to respect the default query args specified when the taxonomy was registered.
  2. If no post ID is given, it uses `get_terms()`, which does not respect the default query args.

For the practical impact, more background, and a fix in the GB repo, see https://github.com/WordPress/gutenberg/issues/65052 and https://github.com/WordPress/gutenberg/pull/67154.

This ticket was mentioned in PR #7848 on WordPress/wordpress-develop by @Bernhard Reiter.


2 months ago
#2

  • Keywords has-patch added

See https://github.com/WordPress/gutenberg/pull/67154. More details to follow.

TODO:

  • [ ] Test coverage

Trac ticket: https://core.trac.wordpress.org/ticket/62500

#3 @Bernhard Reiter
2 months ago

  • Description modified (diff)

@Bernhard Reiter commented on PR #7848:


8 weeks ago
#4

I'll go ahead and merge this per https://github.com/WordPress/gutenberg/pull/67154#pullrequestreview-2454037832:

[T]he Core backport in https://github.com/WordPress/wordpress-develop/pull/7848 also makes perfect sense. The REST controller should apply the taxonomy's default args.

#5 @Bernhard Reiter
8 weeks ago

  • Owner set to Bernhard Reiter
  • Resolution set to fixed
  • Status changed from new to closed

In 59458:

REST API: Terms: Respect taxonomy's default query args.

It is possible to supply a set of default query args to register_taxonomy() which will be used when querying a list of terms -- for example, orderby in order to specify how the resulting list of terms should be sorted.

The Terms REST API controller previously respected these default query args only if the request included a post ID. This changeset makes it so that the default args will also be respected if no post ID is provided.

Props bernhard-reiter, jsnajdr.
Fixes #62500.

Note: See TracTickets for help on using tickets.