Title: About the performance optimize question.(php or sql code)
Last modified: August 20, 2016

---

# About the performance optimize question.(php or sql code)

 *  [kmvan](https://wordpress.org/support/users/kmvan/)
 * (@kmvan)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/about-the-performance-optimize-questionphp-or-sql-code/)
 * As you know. In the query loop, the database query number will increase when 
   every thumbnail shows.
 * For example the queries is 100+ if there are 100 posts in a page,like the code:
 *     ```
       <?php
       $args = array(
       	'orderby' => 'rand',
       	'posts_per_page' => 100,
       );
       $wp_query = new WP_Query($args);
       while($wp_query->have_posts()):$wp_query->the_post();
       	echo get_the_post_thumbnail();
       endwhile;
       echo '<br/>The queries is: ' . get_num_queries();
       ?>
       ```
   
 * Above code, you can get a large of database queries number(at least 100+). It
   is a big problem of performance. Do you think?
 * So, I figured out a idea to optimize it but i don’t know how to write the code.
   Please see my idea:
    As you know, type `print_r($post)` , it will show the stdClass
   object of global $post in loop. Like this:
 *     ```
       stdClass Object
       (
           [ID] => 5915
           [post_author] => 1
           [post_date] => 2011-08-11 11:19:21
           [post_date_gmt] => 2011-08-11 03:19:21
           [post_content] => just_for_a_test_content
           [post_title] => just_for_a_test_title
           [post_excerpt] =>
           [post_status] => publish
           [comment_status] => open
           [ping_status] => open
           [post_password] =>
           [post_name] => just_for_a_test
           [to_ping] =>
           [pinged] =>
           [post_modified] => 2011-08-11 11:19:21
           [post_modified_gmt] => 2011-08-11 03:19:21
           [post_content_filtered] =>
           [post_parent] => 0
           [guid] => http://192.168.1.118/?p=5915
           [menu_order] => 0
           [post_type] => post
           [post_mime_type] =>
           [comment_count] => 18
           [filter] => raw
       )
       ```
   
 * As you see, the stdClass object is not include `[_wp_attached_file]`. So I want
   to put the `[_wp_attached_file]` join into the stdClass. And after that I can
   use the code of `$post->_wp_attached_file` to show thumbnail url. But how to 
   join and how to write the php or sql code?
 * I have a little idea. Maybe can use the code `left join ****` and `add_filter('
   posts_join',***)`….
 * Oh, please for help. Will you have a happy day 🙂

The topic ‘About the performance optimize question.(php or sql code)’ is closed 
to new replies.

## Tags

 * [code](https://wordpress.org/support/topic-tag/code/)
 * [php](https://wordpress.org/support/topic-tag/php/)
 * [post](https://wordpress.org/support/topic-tag/post/)
 * [sql](https://wordpress.org/support/topic-tag/sql/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [kmvan](https://wordpress.org/support/users/kmvan/)
 * Last activity: [14 years, 9 months ago](https://wordpress.org/support/topic/about-the-performance-optimize-questionphp-or-sql-code/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
