Title: Speed problem on loading, PHP code with multiple queries in loop
Last modified: September 1, 2016

---

# Speed problem on loading, PHP code with multiple queries in loop

 *  [MarieveC](https://wordpress.org/support/users/marievec/)
 * (@marievec)
 * [9 years, 10 months ago](https://wordpress.org/support/topic/speed-problem-on-loading-php-code-with-multiple-queries-in-loop/)
 * Hi,
    Sorry in advance for my bad english. I’ve created a code in PHP (in the 
   page \wp-content\themes\my-theme\woocommerce\myaccount\my-account.php) to see
   every products entered in WooCommerce.
 * Here is my code:
 * `
    $tous_produits = array(); $args=array( 'post_type' => 'product', 'post_status'
   => 'publish', 'posts_per_page' => -1, 'caller_get_posts'=> 1 );
 * $my_query = null;
    $my_query = new WP_Query($args); if( $my_query->have_posts()){
   while ($my_query->have_posts()) : $my_query->the_post(); $produit_id = get_the_ID();
   $product = new WC_Product( $produit_id );
 *  $tous_produits[$produit_id]['title'] = get_the_title();
    $tous_produits[$produit_id]['
   description'] = get_post_field('post_content', $produit_id); $tous_produits[$
   produit_id]['Lien_Photo'] = $product->get_attribute( 'Lien_Photo' ); $tous_produits[
   $produit_id]['Lien_Specsheet'] = $product->get_attribute( 'Lien_Specsheet' );
   $tous_produits[$produit_id]['Photometrie'] = $product->get_attribute( 'Photometrie');
   $tous_produits[$produit_id]['ID_Famille'] = $product->get_attribute( 'ID_Famille');
   $tous_produits[$produit_id]['ID_Sous_Famille'] = $product->get_attribute( 'ID_Sous_Famille');
   $tous_produits[$produit_id]['ID_Manufacturier'] = $product->get_attribute( 'ID_Manufacturier');
   $tous_produits[$produit_id]['ID_Marque'] = $product->get_attribute( 'ID_Marque');
   $tous_produits[$produit_id]['ID_Serie'] = $product->get_attribute( 'ID_Serie');
   $tous_produits[$produit_id]['ID_Voltage'] = $product->get_attribute( 'ID_Voltage');
   $tous_produits[$produit_id]['ID_Source'] = $product->get_attribute( 'ID_Source');
   $tous_produits[$produit_id]['ID_Type_de_source'] = $product->get_attribute( '
   ID_Type_de_source' ); $tous_produits[$produit_id]['ID_Installation'] = $product-
   >get_attribute( 'ID_Installation' ); $tous_produits[$produit_id]['guide_stock']
   = $product->get_attribute( 'ID_GD' ); $tous_produits[$produit_id]['Prix_Budget']
   = $product->get_attribute( 'Prix_Budget' ); $tous_produits[$produit_id]['Lumen_emis']
   = $product->get_attribute( 'Lumen_emis' ); $tous_produits[$produit_id]['Wattage']
   = $product->get_attribute( 'Wattage' ); $tous_produits[$produit_id]['id_es'] 
   = $product->get_attribute( 'ID_ES' ); $tous_produits[$produit_id]['id_dlc'] =
   $product->get_attribute( 'ID_DLC' ); $tous_produits[$produit_id]['id_dlcp'] =
   $product->get_attribute( 'ID_DLCP' ); endwhile; } wp_reset_query();
 * My problem is a speed problem, the page takes like 10 seconds to load. I have
   more than 600 products, so the code enters the loop more than 600 times and do
   multiple queries inside the loop, like get_attributes. The thing is that I need
   to have the infos of all my products because I have to show advanced filters 
   with all the products attributes that exist.
 * I’ve optimised my database tables, I haven’t see a significant change in the 
   loading speed.
 * Is there a way to speed up the loading? Thanks for sharing your ideas! 🙂

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

 *  Moderator [t-p](https://wordpress.org/support/users/t-p/)
 * (@t-p)
 * [9 years, 10 months ago](https://wordpress.org/support/topic/speed-problem-on-loading-php-code-with-multiple-queries-in-loop/#post-7656661)
 * Are you using woocommerce plugin? If so, I recommend asking in this plugin’s 
   dedicated support sub-forum for better results so its developers and users can
   help you with this:
    [http://wordpress.org/support/plugin/woocommerce](http://wordpress.org/support/plugin/woocommerce)
 *  Thread Starter [MarieveC](https://wordpress.org/support/users/marievec/)
 * (@marievec)
 * [9 years, 10 months ago](https://wordpress.org/support/topic/speed-problem-on-loading-php-code-with-multiple-queries-in-loop/#post-7656676)
 * Thank you Tara, I’ll do that !

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

The topic ‘Speed problem on loading, PHP code with multiple queries in loop’ is 
closed to new replies.

## Tags

 * [attributes](https://wordpress.org/support/topic-tag/attributes/)
 * [loop](https://wordpress.org/support/topic-tag/loop/)
 * [products](https://wordpress.org/support/topic-tag/products/)
 * [query](https://wordpress.org/support/topic-tag/query/)
 * [speed](https://wordpress.org/support/topic-tag/speed/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [MarieveC](https://wordpress.org/support/users/marievec/)
 * Last activity: [9 years, 10 months ago](https://wordpress.org/support/topic/speed-problem-on-loading-php-code-with-multiple-queries-in-loop/#post-7656676)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
