Commit 99c6067c4d for wordpress.org

commit 99c6067c4db08d45201c4e3899f4dac80f8057b2
Author: jorbin <jorbin@git.wordpress.org>
Date:   Wed Dec 2 22:11:49 2026 +0000

    Rewrite Rules: Use cached max post ID from all object caches.

    Some persistent object cache drop-ins return integers as numeric strings, so the strict `is_int()` check in `wp_get_random_content_sample_ids()` never matched the cached value. This caused the query for the highest post ID to run on every random content request. The cached value is now accepted when it is numeric.

    Developed in: https://github.com/WordPress/wordpress-develop/pull/16372

    Follow-up to r65542.

    Props peterwilsoncc, jorbin.
    Fixes #66894. See #66654, #64498.

    Built from https://develop.svn.wordpress.org/trunk@65867


    git-svn-id: http://core.svn.wordpress.org/trunk@64896 1a063a9b-81f0-0310-95a4-ce76da25c4cd

diff --git a/wp-includes/query.php b/wp-includes/query.php
index 8256ef2285..3c34307bee 100644
--- a/wp-includes/query.php
+++ b/wp-includes/query.php
@@ -1453,11 +1453,14 @@ function wp_get_random_content_sample_ids(): array {

 	$max_id = wp_cache_get( 'max_post_id', 'random-content' );

-	if ( ! is_int( $max_id ) ) {
+	// Some object cache drop-ins return integers as numeric strings, so is_int() cannot be used.
+	if ( ! is_numeric( $max_id ) || $max_id < 0 ) {
 		$max_id = (int) $wpdb->get_var( "SELECT MAX(ID) FROM {$wpdb->posts}" );
 		wp_cache_set( 'max_post_id', $max_id, 'random-content', 10 * MINUTE_IN_SECONDS );
 	}

+	$max_id = (int) $max_id;
+
 	if ( $max_id <= 50 ) {
 		return range( 1, max( 1, $max_id ) );
 	}
diff --git a/wp-includes/version.php b/wp-includes/version.php
index a367a73069..d839579d75 100644
--- a/wp-includes/version.php
+++ b/wp-includes/version.php
@@ -16,7 +16,7 @@
  *
  * @global string $wp_version
  */
-$wp_version = '7.3-alpha-65866';
+$wp_version = '7.3-alpha-65867';

 /**
  * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.