[wp-trac] [WordPress Trac] #28425: get_permalink passes only post ID to called functions instead of post object

WordPress Trac noreply at wordpress.org
Mon Jun 23 11:38:22 UTC 2014


#28425: get_permalink passes only post ID to called functions instead of post
object
-------------------------------+--------------------------
 Reporter:  arnee              |       Owner:
     Type:  enhancement        |      Status:  new
 Priority:  normal             |   Milestone:  4.0
Component:  Posts, Post Types  |     Version:  trunk
 Severity:  normal             |  Resolution:
 Keywords:  has-patch          |     Focuses:  performance
-------------------------------+--------------------------

Comment (by kovshenin):

 Replying to [comment:8 arnee]: I'm not sure that's a valid use case.

 If you need the post with the ID 21278, you're better off with `get_post(
 21278 )`. If you're looking for pages by path, title, etc, you should be
 using `get_page_by_*` or `WP_Query`. All of these leverage object caching,
 which prevents further querying of the same posts regardless of the
 context (the same post can appear in a widget for example).

 Furthermore, when using these in an environment with persistent object
 caching, there's a high chance you don't need to hit the database even
 once, especially if you're simply querying by ID.

 Also, passing an object instead of the ID doesn't really solve much. The
 `page_link` and `attachment_link` filters pass the post ID, so there's a
 chance anything attached to those filters will run `get_post` with an ID
 anyway.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/28425#comment:9>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list