Make WordPress Core

Opened 3 years ago

Last modified 19 months ago

#42949 new enhancement

wp_attachment_is() forces the page to get new instance of post

Reported by: bowlerman235 Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Posts, Post Types Keywords: reporter-feedback close
Focuses: performance Cc:


In the wp_attachment_is function, the signature allows for the post to be passed in as either ID or object. However, if you pass and an instance of a post object in, the current code forces you to retrieve another copy of the post object. It should use the object passed in to prevent unnecessary database calls.

Change History (2)

#1 @dd32
3 years ago

  • Keywords reporter-feedback close added

Hi @bowlerman235,

wp_attachment_is() does make a call to get_post() however in the event that a WP_Post is passed it'll eventually get passed back. WordPress also includes a in-memory cache so that fetching the same post multiple times by the same ID will not result in more database queries.

If you're seeing something other than the above, can you let us know exactly what you're seeing?

This ticket seems invalid, however I'll wait for your response before closing it for now.

#2 @pento
19 months ago

  • Version trunk deleted
Note: See TracTickets for help on using tickets.