Welcome to WebmasterWorld Guest from 54.158.35.222

Forum Moderators: rogerd & travelin cat

Message Too Old, No Replies

Speed up Wordpress: Prevent original database lookup?

     
12:56 pm on Aug 17, 2011 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



Hello.

I've recently learnt that if you use query_posts in a template file then you are effectively wasting a database lookup, because WordPress has already retrieved the relevant posts from the database before it even reads your template files.

So if it's a category page, WordPress will first grab all of the category posts (based on what the URL is), and then it will read your template file and see the query_post, and then it will be forced to retrieve them all over again.

My site is getting big enough now that i need to save all the queries i can, so i was wondering if anyone knows where the line is in the core files that retrieves the posts BEFORE it reads the template files, so i can stop it from happening. My site is designed in such a way that i always use query_posts, no matter what the URL is, so i dont mind doing away with that original query completely.

any help will be much appreciated
2:11 pm on Aug 17, 2011 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



i figured it out... if anyone wants to know here is what you do. It knocks off a couple of database queries, but it only works if you go on to call query_posts in your template file.

on the /index.php file in the root, just add
$parse_query_allow = 'no';


on the wp-includes/query.php file, find the line
$this->request = " SELECT $found_rows $distinct $fields FROM $wpdb->posts $join WHERE 1=1 $where $groupby $orderby $limits";


and replace it with
global $parse_query_allow;
if(!isset($_GET['page_id'])&&!is_single()&&$parse_query_allow=='no'){$parse_query_allow='yes';
}else{
$this->request = " SELECT $found_rows $distinct $fields FROM $wpdb->posts $join WHERE 1=1 $where $groupby $orderby $limits";
}
4:46 pm on Aug 18, 2011 (gmt 0)

WebmasterWorld Senior Member lorax is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



Thanks for the info. I may find that useful soon! :)
4:43 pm on Aug 19, 2011 (gmt 0)

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Anything to increase efficiency in WP is good, but have hacked core code before . . . it's no fun updating them with the updates getting pushed out so often.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month