WordPress.org

Make WordPress Core

Opened 7 months ago

Closed 7 months ago

#52144 closed defect (bug) (fixed)

the $term_ids in function wp_queue_posts_for_term_meta_lazyload is index array

Reported by: denishua Owned by: SergeyBiryukov
Milestone: 5.7 Priority: normal
Severity: normal Version: 4.5
Component: Posts, Post Types Keywords: has-patch needs-testing needs-unit-tests
Focuses: administration, coding-standards Cc:

Description

the $term_ids in function wp_queue_posts_for_term_meta_lazyload is index array,

if ( ! isset( $term_ids[ $term->term_id ] ) ) {

should change to

if ( ! in_array( $term->term_id, $term_ids ) ) {

Attachments (2)

52144.patch (503 bytes) - added by akabarikalpesh 7 months ago.
I just added "if ( ! in_array( $term->term_id, $term_ids ) ) {" in wp-includes/post.php file
52144.diff (509 bytes) - added by akabarikalpesh 7 months ago.

Download all attachments as: .zip

Change History (7)

#1 @SergeyBiryukov
7 months ago

  • Component changed from General to Posts, Post Types
  • Milestone changed from Awaiting Review to 5.7
  • Owner set to SergeyBiryukov
  • Status changed from new to reviewing
  • Version changed from 5.6 to 4.5

Hi there, welcome to WordPress Trac! Thanks for the report.

Introduced in [36566] / #35816. Setting the Version field to 4.5 as the earliest affected version.

@akabarikalpesh
7 months ago

I just added "if ( ! in_array( $term->term_id, $term_ids ) ) {" in wp-includes/post.php file

#2 @akabarikalpesh
7 months ago

  • Focuses administration coding-standards added
  • Keywords has-patch needs-testing needs-unit-tests added

#3 follow-up: @SergeyBiryukov
7 months ago

Thanks for the patch, @akabarikalpesh!

Just noting that we should use a strict type check for in_array(), see [47550] and [47557] / #49542 for more context.

This is controlled by the third parameter of in_array(), so the line would look like this:

if ( ! in_array( $term->term_id, $term_ids, true ) ) {

#4 in reply to: ↑ 3 @akabarikalpesh
7 months ago

Replying to SergeyBiryukov:

Thanks for the patch, @akabarikalpesh!

Just noting that we should use a strict type check for in_array(), see [47550] and [47557] / #49542 for more context.

This is controlled by the third parameter of in_array(), so the line would look like this:

if ( ! in_array( $term->term_id, $term_ids, true ) ) {

I added new .diff file. please check and let me know if any changes

#5 @SergeyBiryukov
7 months ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 49905:

Posts, Post Types: Correct the check for term IDs to be queued for lazy-loading term meta.

This ensures that the $term_ids array in wp_queue_posts_for_term_meta_lazyload() (an indexed array not keyed by ID) does not contain duplicate values.

Props denishua, akabarikalpesh.
Fixes #52144.

Note: See TracTickets for help on using tickets.