WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 6 weeks ago

#42949 closed enhancement (invalid)

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

Reported by: bowlerman235 Owned by:
Milestone: Priority: normal
Severity: normal Version:
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 (3)

#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
2 years ago

  • Version trunk deleted

#3 @hellofromTonya
6 weeks ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

Hello @bowlerman235 and Welcome to Trac!

I'm closing this ticket you opened. Why? It's been over 3 years since feedback was requested.

However, please feel free to reopen and provide us with feedback. Cheers.

Note: See TracTickets for help on using tickets.