WordPress.org

Make WordPress Core

Opened 6 months ago

Last modified 6 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: trunk
Component: Posts, Post Types Keywords: reporter-feedback close
Focuses: performance Cc:

Description

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 (1)

#1 @dd32
6 months 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.

Note: See TracTickets for help on using tickets.