[wp-hackers] WP_Query loop generates a lot of mySQL queries

Dusan Dzurdzic dusan.dzurdzic at gmail.com
Mon Oct 29 19:17:56 UTC 2012


Hello friends,

I would like to start a discussion regarding wp_query() loops, both for 
single loop on a page, or for multiples wp_query() loops on the same page.

I'm creating a template with a few pages. On index page I'm retrieving 
posts from a few different custom post types, with a few wp_query() 
loops. On the other page, eg domain.com/somepage I'm using one loop to 
retrieve certain posts. On that page, I'm producing around 5 mySQL 
queries per returned post (posts_per_page=1), for 5 posts 
(posts_per_page=5) I'm getting around 30 mySQL queries.
On the index page, domain.com, for 4 columns multiple with 5 
posts_per_page, I got around 130 mySQL queries.  Obviously I'm not 
getting an array with posts information.

Is there any way to merge them, or something similar. Maybe another 
approach..   I have pasted my code on pastie, for easy lookup: 
http://pastie.org/5130894 .

I saw few more peoples on wordpress.org/support and 
wordpress.stackexchange.com troubling exact problem, but there were no 
any answer, so I'm writing to You (wp-hackers lists on automattic).

Thanks

Dusan Dzurdzic


More information about the wp-hackers mailing list