homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / WordPress
Forum Library, Charter, Moderators: lorax & rogerd

WordPress Forum

Speed up Wordpress: Prevent original database lookup?

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


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)

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;
$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)

Thanks for the info. I may find that useful soon! :)


 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.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / WordPress
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved