Changeset 60792
- Timestamp:
- 09/22/2025 06:48:39 PM (3 weeks ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/post.php
r60788 r60792 3407 3407 ) { 3408 3408 // Optimized query uses subqueries which can leverage DB indexes for better performance. See #61097. 3409 $query = $wpdb->prepare( 3410 " 3409 $query = " 3411 3410 SELECT post_status, COUNT(*) AS num_posts 3412 3411 FROM ( … … 3419 3418 WHERE post_type = %s AND post_status = 'private' AND post_author = %d 3420 3419 ) AS filtered_posts 3421 ", 3422 $type, 3423 $type, 3424 get_current_user_id() 3425 ); 3420 "; 3421 $args = array( $type, $type, get_current_user_id() ); 3426 3422 } else { 3427 $query = $wpdb->prepare( 3428 " 3423 $query = " 3429 3424 SELECT post_status, COUNT(*) AS num_posts 3430 3425 FROM {$wpdb->posts} 3431 3426 WHERE post_type = %s 3432 ", 3433 $type 3434 ); 3435 } 3436 3437 $query .= ' GROUP BY post_status'; 3438 $results = (array) $wpdb->get_results( $query, ARRAY_A ); 3427 "; 3428 $args = array( $type ); 3429 } 3430 3431 $query .= ' GROUP BY post_status'; 3432 3433 $results = (array) $wpdb->get_results( 3434 $wpdb->prepare( $query, ...$args ), // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- Placeholders are used in the string contained in the variable. 3435 ARRAY_A 3436 ); 3439 3437 $counts = array_fill_keys( get_post_stati(), 0 ); 3440 3438 -
trunk/tests/phpunit/tests/post.php
r60788 r60792 197 197 * 198 198 * @ticket 61097 199 * 199 200 * @covers ::wp_count_posts 200 201 */ … … 223 224 ); 224 225 225 $current_user_id = self::$user_ids['author']; 226 wp_set_current_user( $current_user_id ); 226 wp_set_current_user( self::$user_ids['author'] ); 227 227 228 228 $count = wp_count_posts( $post_type, 'readable' );
Note: See TracChangeset for help on using the changeset viewer.