| Speed up Wordpress: Prevent original database lookup?
|
londrum

msg:4352496 | 12:56 pm on Aug 17, 2011 (gmt 0) | 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
|
londrum

msg:4352685 | 2:11 pm on Aug 17, 2011 (gmt 0) | 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"; }
|
lorax

msg:4353162 | 4:46 pm on Aug 18, 2011 (gmt 0) | Thanks for the info. I may find that useful soon! :)
|
rocknbil

msg:4353499 | 4:43 pm on Aug 19, 2011 (gmt 0) | 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.
|
|
|