How to optimize ‘select found_rows()’ query? Several ‘high load average’ alerts daily

This should not break pagination: add_filter(‘pre_get_posts’, ‘optimized_get_posts’, 100); function 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 ) ); if($wp_query->query_vars[‘posts_per_page’] <= 0) { $wp_query->max_num_pages = 0; } else { $wp_query->max_num_pages = ceil($wp_query->found_posts … Read more

How to disable cache for the content returned by a shortcode

As the caching usually doesn’t work on parts of the page, but on the whole page, you can’t have it just not cache that specific part (well, you could use ESI/Edge Side Includes, but that’s not an option for all implementations). What you could to is write a hook that checks whether these shortcodes are … Read more