Make WordPress Core

Opened 4 years ago

Closed 5 months ago

Last modified 2 months ago

#54125 closed defect (bug) (worksforme)

Rest API tax_relation=OR doesn't seem to work correctly

Reported by: roverlap's profile roverlap Owned by:
Milestone: Priority: normal
Severity: major Version: 5.8
Component: REST API Keywords: reporter-feedback
Focuses: rest-api Cc:

Description

Let's say we have posts of a custom post type.

Post 1 has custom-tax1 with ID1 and custom-tax2 with ID2.
Post 2 has custom-tax2 with ID2.
Post 3 has custom-tax1 with ID3.
Post 4 has no custom taxonomies attached.

When querying

/wp/v2/custompost?&_fields=id,title&custom-tax1=ID&custom-tax2=ID2

it returns only Post 1 as expected.

/wp/v2/custompost?&_fields=id,title&custom-tax2=ID2

returns Post 1 and Post 2 as expected

Querying

/wp/v2/custompost?&_fields=id,title&custom-tax1=ID1&custom-tax2=ID2&tax_relation=OR

I expect it to return Post 1 and Post 2 as well, but instead it returns all 4 Posts. As soon as tax_relation=OR is added to the query, it seems all prior tax queries are just ignored.

Unless I'm misreading this https://make.wordpress.org/core/2020/02/29/rest-api-changes-in-5-4/ and it should somehow work differently.

Change History (3)

#1 @antonvlasenko
8 months ago

  • Keywords reporter-feedback added

Reproduction report.

Environment

  • WordPress: 6.7-alpha-58576-src
  • PHP: 7.3.33
  • Server: Apache/2.4.57 (Unix) PHP/7.3.33
  • Database: mysqli (Server: 5.7.43 / Client: mysqlnd 5.0.12-dev)
  • Browser: Safari 17.6 (macOS)
  • Theme: Twenty Twenty-Three 1.5
  • MU-Plugins: None activated
  • Plugins:
    • WordPress Beta Tester 3.5.3

Actual Results

  • ❌ Bug cannot be reproduced.

Additional Notes

I've created four posts with related term objects. When executing the following REST API query:
/wp/v2/custompost?&_fields=id,title&custom-tax1=ID1&custom-tax2=ID2&tax_relation=OR

the endpoint correctly returned the first two post objects. The database query executed was:

SELECT SQL_CALC_FOUND_ROWS  wp_posts.ID
					 FROM wp_posts  LEFT JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id)
					 WHERE 1=1  AND ( 
  wp_term_relationships.term_taxonomy_id IN (2) 
  OR 
  wp_term_relationships.term_taxonomy_id IN (3)
) AND wp_posts.post_type = 'custompost' AND ((wp_posts.post_status = 'publish'))
					 GROUP BY wp_posts.ID
					 ORDER BY wp_posts.post_date DESC
					 LIMIT 0, 10

and it returned correct results.

Are you able to reproduce this bug on the latest (6.6) WordPress version, @roverlap? If not, could this ticket be closed?

#2 @antonvlasenko
5 months ago

  • Resolution set to worksforme
  • Status changed from new to closed

Thank you for your contribution to WordPress, @roverlap!
After reviewing the ticket, I couldn’t reproduce the issue you reported.
Since it’s been over two months without any further updates, I’ll be closing the ticket for now.
However, if you come across more information or if the issue shows up again, feel free to reopen it.

And thank you for submitting your first ticket! 🎉
Looking forward to seeing more from you in the future.

#3 @desrosj
2 months ago

  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.