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

Multiple post queries -category,posts per page,orderby

You are passing the cat parameter twice– the second time is empty. $page_query = new WP_Query( ‘post_type=post&cat=145’. ‘&posts_per_page=-1&cat’ . // <– here ‘&orderby=date&order=asc’ ); Maybe it is just me, but I find those query-string-like parameters hard to read and hard to keep straight. I’d advise you to create a proper array. $page_query = new WP_Query( … Read more

get_next_posts_link() stops displaying at page 4

I don’t know where $era_opts comes from but a filter on pre_get_posts should do this and preserve your pagination. function era_blog_cats_wpse_103587($qry) { if ($qry->is_page(‘your-page’) && is_main_query()) { $era_opts = get_option(‘era_opts’); // assuming that era_opts are options $blogcats = $era_opts[‘era_opts_blog_thecats’]; if(!empty($era_opts[‘era_opts_blog_thecats’])) { $qry->set(‘category__in’, $blogcats); } } } add_action(‘pre_get_posts’,’era_blog_cats_wpse_103587′); I made several assumptions about your data, but … Read more

query_posts not working after wordpress 3.7 update

Get rid of query_posts() in your template file. Instead, you need to filter the main query object, via pre_get_posts. The following function will exclude the specified category and change posts per page for the main blog posts index: function wpse102566_pre_get_posts( $query ) { if ( is_home() && $query->is_main_query() ) { $query->set( ‘category__not_in’, array( ‘103’ ) … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)