Make WordPress Core

Opened 3 years ago

Closed 3 months ago

#58189 closed defect (bug) (fixed)

post_type parameter in update_post_caches() accepts more than a single post type

Reported by: DrewAPicture Owned by: spacedmonkey
Priority: normal Milestone: 7.1
Component: Cache API Version:
Severity: trivial Keywords: has-patch commit
Cc: Focuses: docs

Description

In update_post_caches(), the post_type parameter is documented as only accepting a single post type, which is inaccurate. It actually accepts a single post type, 'any' for any post type, and also an array of post types.

Attachments (2)

58189.diff​ (1.2 KB ) - added by DrewAPicture 3 years ago.
58189.2.diff​ (1.2 KB ) - added by peterwilsoncc 3 months ago.

Download all attachments as: .zip

Change History (8)

@DrewAPicture
3 years ago

#1 @spacedmonkey
3 years ago

I like this @DrewAPicture !

Something I was wonder to make this clearer. Should we change this line

function update_post_caches( &$posts, $post_type = 'post', $update_term_cache = true, $update_meta_cache = true ) {

to

function update_post_caches( &$posts, $post_types = array( 'post' ), $update_term_cache = true, $update_meta_cache = true ) {

It gets converted to an array on line 7399 anyway.

I think it maybe would be clearer, if it was post types.

#2 @DrewAPicture
3 years ago

@spacedmonkey I feel like we should leave the parameter as-is. Yes we convert it to an array anyway with $ptypes but it strikes me that accepting multiples is the exception not the rule.

#3 @spacedmonkey
5 months ago

  • Milestone Awaiting Review → 7.1
  • Owner set to spacedmonkey
  • Status new → assigned

#4 @spacedmonkey
5 months ago

  • Keywords commit added

#5 @peterwilsoncc
3 months ago

A minor change in 58189.2.diff​ to document the parameter as string|string[].

#6 @peterwilsoncc
3 months ago

  • Resolution → fixed
  • Status assigned → closed

In 62799:

Cache API: Correct docs for update_post_caches() parameters.

Documents the $post_type parameter accepts both a single post type as a string or multiple post types as an array.

Props drewapicture, spacedmonkey.
Fixes #58189.

Note: See TracTickets for help on using tickets.