I acquainted a client who designed his own fashion magazine site. My company handed the project to me to make it with WordPress. When I was making the complete template for the site, I found his complete thought: and it's completely eerie for me; because the design for the home page had many more blocks, not less than 20 blocks, and each of the blocks demands a new WP_Query() (and just now from this thread I was known that I's right making new WP_Query() for each of the blocks).

And the final product was damn slow - as I suspected.

I'm not a WordPress master, so as I understood WP_Query() is whenever it's called, it hits the db with it's query and retrieve the data as per the query. So in this site, in the Home Page it's hitting 20 times and then retrieving the data and that makes it slower.

With this scenario, I's thinking of some Speeding Up solutions, like:

  • Separating the loop for each of the posts with a common function so that it loads a single time with different parameters each of the time
  • Some basic CSS things to speed up the layout
  • Separating the common things into different files and include them with get_template_part(), so that the common thing will load a single time and echo multiple times wherever it's necessary
  • Using LazyLoad to the site images to let 'em not hamper the site speed when the content and layout is important first
  • Caching the site's content
  • WP Smush.it the images
  • If possible and doesn't create conflict then using the .js compression

With these thoughts, I may be wrong with much of their concepts, but I found them logically good.

So the ultimate questions are:

  • What can be done further to speed up a site with multiple queries (i.e. 20 different queries)?
  • Or, is there any better solution instead of using WP_Query() for each of the queries?
  • 1
    1st point in list don't change anything: if the common function call a WP_Query, the db queries are exactly the same. The other points can speed up the site, but aren't related to the queries, so do them if you want, but are valid things indifferently for a page with 1 or 20 queries... The only query-related point in your list is "Caching the site's content": a good point for sure, but in my experience, the queries in a page can be reduced in number merging them and using logic to separate posts and show them in right place. 20 queries are really an high number for one single page.
    – gmazzap
    Commented Sep 13, 2013 at 9:34

2 Answers 2


You must use cache systems.without caching, your site will be slowly.use APC or memcache for increase speed of your home page.

or use redis.


save queries into transients for a specific time by using set_transient(); and retrieve saved query using get_transient(); this will reduce your site's loading time too much, as you stated you are using 20 queries on a page then you need to set different transients expiration time so all transients don't expire at once.

example usage:

$my_query = get_transient('my_query');

if (!$my_query) {
    // run query
    $args = array(
        // query args

    $my_query = new WP_Query($args);
            // set transient for 3 hours
    set_transient('my_query', $my_query, 60*60*3);

   // run your loop
   if ($my_query->have_posts()) :
        while ($my_query->have_posts()) :
           // do your stuff

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.