Title: a question about WP_query
Last modified: August 21, 2016

---

# a question about WP_query

 *  [lostheaven0809](https://wordpress.org/support/users/lostheaven0809/)
 * (@lostheaven0809)
 * [13 years, 2 months ago](https://wordpress.org/support/topic/a-question-about-wp_query/)
 * i used wp_query class to get posts from a lot of different categories. after 
   that, i checked and my web need 187 queries to database. it’s terrible. i found
   out wp_query class need 5 query to database when it runs. is it right?
    what 
   function i recommend to use when i want to get posts from a lot of different 
   categories?

Viewing 7 replies - 1 through 7 (of 7 total)

 *  [Pioneer Web Design](https://wordpress.org/support/users/swansonphotos/)
 * (@swansonphotos)
 * [13 years, 2 months ago](https://wordpress.org/support/topic/a-question-about-wp_query/#post-3791009)
 * Have you run any site optimization tools? that is a lot of queries, but not unheard
   of…
 * Also, you can reduce that by not loading say, 187 posts on a page – are you paginating
   the posts?
 * site link?
 *  Thread Starter [lostheaven0809](https://wordpress.org/support/users/lostheaven0809/)
 * (@lostheaven0809)
 * [13 years, 2 months ago](https://wordpress.org/support/topic/a-question-about-wp_query/#post-3791023)
 * i design my theme by myself. not use any outside plugin.
    i code:
 *     ```
       $query = new WP_Query(array('posts_per_page' => 10, 'category_name' => 'tin-tuc'));
       ....
       wp_reset_postdata();
       ```
   
 *     ```
       $query = new WP_Query(array('posts_per_page' => 10, 'category_name' => 'tai-lieu'));
       ....
       wp_reset_postdata();
       ```
   
 * and a lot of alike snippets. i get all of them out and then put into one by one.
   i found out every snippet need 5 query to database.
 * site link: [http://www.dientudangkhoa.com/](http://www.dientudangkhoa.com)
 * thanks.
 *  [Pioneer Web Design](https://wordpress.org/support/users/swansonphotos/)
 * (@swansonphotos)
 * [13 years, 2 months ago](https://wordpress.org/support/topic/a-question-about-wp_query/#post-3791028)
 * Do this:
 * Add this to the footer, just above `</body>`:
 * `<div><?php echo get_num_queries() ?> queries in <?php echo timer_stop(0) ?> 
   seconds</div>`
 * This will give you the # of queries on each page (with footer, of course) and
   how long in seconds to make them…
 * If on a shared host, this can vary (the time)…report back so we can see..
 *  Thread Starter [lostheaven0809](https://wordpress.org/support/users/lostheaven0809/)
 * (@lostheaven0809)
 * [13 years, 2 months ago](https://wordpress.org/support/topic/a-question-about-wp_query/#post-3791031)
 * it put in the footer tag. you can see at the Menu section in footer
 *  [Pioneer Web Design](https://wordpress.org/support/users/swansonphotos/)
 * (@swansonphotos)
 * [13 years, 2 months ago](https://wordpress.org/support/topic/a-question-about-wp_query/#post-3791033)
 * Looks like you added text…where is the div?
 * [http://validator.w3.org/check?uri=http%3A%2F%2Fwww.dientudangkhoa.com%2F&charset=%28detect+automatically%29&doctype=Inline&group=0&ss=1](http://validator.w3.org/check?uri=http%3A%2F%2Fwww.dientudangkhoa.com%2F&charset=%28detect+automatically%29&doctype=Inline&group=0&ss=1)
 *  Thread Starter [lostheaven0809](https://wordpress.org/support/users/lostheaven0809/)
 * (@lostheaven0809)
 * [13 years, 2 months ago](https://wordpress.org/support/topic/a-question-about-wp_query/#post-3791035)
 * i think validator.w3.ord website can only check html error. not related to query
   to database. if it have error with html, it will not affect to php and mySQL.
 *  [Pioneer Web Design](https://wordpress.org/support/users/swansonphotos/)
 * (@swansonphotos)
 * [13 years, 2 months ago](https://wordpress.org/support/topic/a-question-about-wp_query/#post-3791091)
 * You should try to make a query and follow that with [get_categories](http://codex.wordpress.org/Function_Reference/get_categories)…
   once you have pulled the posts, run the functions but only when needed (per page
   template in use)
 * [http://codex.wordpress.org/The_Loop#Multiple_Loops_Example_2](http://codex.wordpress.org/The_Loop#Multiple_Loops_Example_2)

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘a question about WP_query’ is closed to new replies.

## Tags

 * [wp_query](https://wordpress.org/support/topic-tag/wp_query/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 7 replies
 * 2 participants
 * Last reply from: [Pioneer Web Design](https://wordpress.org/support/users/swansonphotos/)
 * Last activity: [13 years, 2 months ago](https://wordpress.org/support/topic/a-question-about-wp_query/#post-3791091)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
