• I want to disable Disable SQL_CALC_FOUND_ROWS with Pagination. For that purpose, i am using the following code from SQL_CALC_FOUND_ROWS but due to that code pagination not working. How i do this or how to improve below code?

    if ( ! function_exists( 'oz_optimized_get_posts' ) ): function oz_optimized_get_posts() { global $wp_query, $wpdb;
    
    $wp_query->query_vars['no_found_rows'] = 1;
    $wp_query->found_posts = $wpdb->get_var( "SELECT COUNT(*) FROM wp_posts WHERE 1=1 AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private')" );
    $wp_query->found_posts = apply_filters_ref_array( 'found_posts', array( $wp_query->found_posts, &$wp_query ) );
    
    $posts_per_page = ( ! empty( $wp_query->query_vars['posts_per_page'] ) ? $wp_query->query_vars['posts_per_page'] : get_option( 'posts_per_page' ) );
    $wp_query->max_num_pages = ceil( $wp_query->found_posts / $posts_per_page );
    
    return $wp_query;
    } add_filter( 'pre_get_posts', 'oz_optimized_get_posts', 100 ); endif;

The topic ‘Disable SQL_CALC_FOUND_ROWS with Pagination’ is closed to new replies.