WordPress.org

Make WordPress Core

Ticket #15805: 15805.patch

File 15805.patch, 810 bytes (added by solarissmoke, 3 years ago)

Cache get_page_by_title queries

  • wp-includes/post.php

     
    31693169 */ 
    31703170function get_page_by_title($page_title, $output = OBJECT, $post_type = 'page' ) { 
    31713171        global $wpdb; 
    3172         $page = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_title = %s AND post_type= %s", $page_title, $post_type ) ); 
     3172         
     3173        $cache_id = "page_title_$page_title"; 
     3174         
     3175        if( false === $page = wp_cache_get( $cache_id, 'posts' ) ) { 
     3176                $page = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_title = %s AND post_type= %s", $page_title, $post_type ) ); 
     3177                wp_cache_add( $cache_id, $page, 'posts' ); 
     3178        } 
     3179         
    31733180        if ( $page ) 
    31743181                return get_page($page, $output); 
    31753182