[wp-trac] [WordPress Trac] #43661: Un-neccessary call to get_post() in get_body_class() method

WordPress Trac noreply at wordpress.org
Tue Aug 22 12:27:58 UTC 2023


#43661: Un-neccessary call to get_post() in get_body_class() method
-------------------------------------+-------------------------------------
 Reporter:  pat@…                    |       Owner:  spacedmonkey
     Type:  enhancement              |      Status:  assigned
 Priority:  normal                   |   Milestone:  6.4
Component:  Posts, Post Types        |     Version:  4.9.4
 Severity:  normal                   |  Resolution:
 Keywords:  has-patch needs-testing  |     Focuses:  multisite, performance
-------------------------------------+-------------------------------------
Changes (by SergeyBiryukov):

 * keywords:  has-patch 2nd-opinion needs-testing => has-patch needs-testing


Comment:

 Replying to [comment:4 oglekler]:
 > there are also several calls for `$wp_query->get_queried_object()` in
 the same function, can we remove them as well?

 It looks like they are all in different conditional branches, so each of
 them is only executed once, depending on which conditional is true:
 `is_author()`, `is_category()`, etc. So I think those are fine to keep as
 is for now.

 > And actually it can be:
 >
 > {{{#!php
 > $post      = $wp_query->get_queried_object();
 > $post_id   = $post->ID;
 > }}}

 That makes sense to me, thanks!

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


More information about the wp-trac mailing list