[wp-trac] [WordPress Trac] #63263: check if exists before accessing object properties of $post->comment_count

WordPress Trac noreply at wordpress.org
Wed Oct 22 18:26:59 UTC 2025


#63263: check if exists before accessing object properties of $post->comment_count
---------------------------------------------+--------------------------
 Reporter:  Presskopp                        |       Owner:  westonruter
     Type:  defect (bug)                     |      Status:  assigned
 Priority:  normal                           |   Milestone:  6.9
Component:  General                          |     Version:
 Severity:  normal                           |  Resolution:
 Keywords:  needs-test-info has-screenshots  |     Focuses:
---------------------------------------------+--------------------------

Comment (by johnjamesjacoby):

 Replying to [comment:21 westonruter]:
 > It wouldn't hurt to also include a `$post instanceof WP_Post` check as
 well, even though it is most likely that the global will have been set.
 There're no guarantees!

 The surrounding code attempts to guarantee it here by mocking an empty
 WP_Post object:

 https://core.trac.wordpress.org/browser/trunk/src/wp-includes/general-
 template.php#L3330

 It just did not factor in the situation where a Singular queried object
 (home page) would simultaneously result in “no posts”. 🤣

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


More information about the wp-trac mailing list