Make WordPress Core

Changeset 60654

Timestamp:
08/20/2025 02:59:41 PM (7 weeks ago)
Author:
SergeyBiryukov
Message:

Posts, Post Types: Avoid an extra database query in WP_Post for a negative post ID.

Follow-up to [21559].

Props bor0, akeda, SergeyBiryukov.
Fixes #63850.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-post.php

    r59816 r60654  
    234234
    235235        $post_id = (int) $post_id;
    236         if ( ! $post_id ) {
     236        if ( $post_id <= 0 ) {
    237237            return false;
    238238        }
  • trunk/tests/phpunit/tests/post/wpPost.php

    r49603 r60654  
    4343
    4444    /**
     45     * @ticket 63850
     46     */
     47    public function test_get_instance_should_not_perform_database_query_for_negative_number() {
     48        $num_queries = get_num_queries();
     49        $found       = WP_Post::get_instance( -self::$post_id );
     50
     51        $this->assertSame( $num_queries, get_num_queries() );
     52    }
     53
     54    /**
    4555     * @ticket 37738
    4656     */
Note: See TracChangeset for help on using the changeset viewer.