Make WordPress Core

Opened 9 days ago

Last modified 9 days ago

#61957 new enhancement

Taxonomies: Allow querying for all posts with any term of a given taxonomy

Reported by: bernhard-reiter's profile Bernhard Reiter Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Taxonomy Keywords: has-patch
Focuses: Cc:

Description

Consider an example taxonomy, e.g. projects, with possible terms film, tv, etc.

Upon registering such a taxonomy -- and creating those terms -- WordPress provides us with routes, such as /projects/film and /projects/tv, which will display all posts that have those respective terms assigned.

However, there's no straight-forward way to show all posts that have any term from the projects taxonomy assigned (in this example: all film and tv projects at once). Instead, depending on the chosen permalink structure, the /projects route will be typically understood by WP as the slug of a page or post; and if no page or post with such a slug exists, it will 404.

I believe that there might be a need to support such a "root taxonomy route" -- for lack of a better word. In terms of template resolution, that route should use all the matching taxonomy related templates (i.e. taxonomy-$taxonomy, taxonomy, archive, and index). This applies to both Classic Themes, and Block Themes.

Permalinks in WordPress are, of course, not the canonical representation of routes; query strings are. For example, /projects/film translates to ?projects=film. Fortunately, while syntax like ?projects= (with no value assigned) or simply ?projects is currently not supported by WP, they aren't strictly disallowed by the URI RFC.

Change History (4)

#1 @Bernhard Reiter
9 days ago

With a feature like this, we could have a taxonomy-$taxonomy template that contains, among other things, a block that lists and links to all terms in the given taxonomy. That way, users arriving at /projects will be able to easily filter for films (/projects/film) or TV works (/projects/tv).

This could then be refined further by using the Query Loop block's support of client-side navigation -- meaning that the page at /projects would allow for client-side filtering by existing terms.

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


9 days ago
#2

  • Keywords has-patch added

WIP, Details to follow.

TODO:

  • [ ] Add rewrite rule to map /tax to ?tax.

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

@Bernhard Reiter commented on PR #7271:


9 days ago
#3

The Query Monitor plugin has come in _very_ handy while working on this.

@Bernhard Reiter commented on PR #7271:


9 days ago
#4

Noting here that if we don't want to implement this kind of behavior universally for all taxonomies, we could add an argument to register_taxonomy to control it.

Note: See TracTickets for help on using tickets.