Make WordPress Core

Opened 19 months ago

Closed 10 months ago

Last modified 7 months ago

#25284 closed enhancement (fixed)

Support tax queries using term_taxonomy_id without specifying a taxonomy

Reported by: helen Owned by: wonderboymusic
Milestone: 4.0 Priority: normal
Severity: normal Version:
Component: Taxonomy Keywords: has-patch needs-unit-tests
Focuses: Cc:


Taxonomy queries using term_taxonomy_id don't actually check to see if the terms exist in the specified taxonomy. So long as an existing taxonomy is used, it allows you to query across multiple taxonomies in one segment of the query. We should officially support not specifying a taxonomy if using term_taxonomy_id as the field, and do the magic to make include_children work.

Attachments (2)

25284.diff (4.9 KB) - added by helen 19 months ago.
25284.2.diff (4.7 KB) - added by helen 17 months ago.

Download all attachments as: .zip

Change History (8)

comment:1 @helen19 months ago

Working on patch, including unit tests to make sure crazy things being done don't break in the future.

@helen19 months ago

@helen17 months ago

comment:3 @helen17 months ago

  • Keywords has-patch needs-testing added

Having now worked on this and thought about it some more, I don't think include_children should work without taxonomy specified so long as we have shared terms. It's backward, and if you're taking the time to get the term_taxonomy_id, you should get the children that you want while you're at it.

Patch includes the start of some unit tests. They need to be fleshed out to encompass all possible scenarios, and can probably be written better. Still new to that part.

comment:4 @wonderboymusic11 months ago

  • Keywords needs-unit-tests added; needs-testing removed
  • Milestone changed from Awaiting Review to 4.0

@helen and I chatted about this - want to look at this during our Taxonomy work in 4.0

comment:5 @wonderboymusic10 months ago

  • Owner set to wonderboymusic
  • Resolution set to fixed
  • Status changed from new to closed

In 28562:

When adding queries to tax_query: if the query's field is term_taxonomy_id, don't require taxonomy to be specified. In WP_Tax_Query::transform_query(), $query['taxonomy'] is never checked for the 'term_taxonomy_id' case because 'term_taxonomy_id' is the primary key being looked up.

Adds unit tests.

Props helen.
Fixes #25284.

comment:6 @ircbot7 months ago

This ticket was mentioned in IRC in #wordpress-dev by helen. View the logs.

Note: See TracTickets for help on using tickets.