Title: Performance problem &#8211; many database queries
Last modified: August 30, 2016

---

# Performance problem – many database queries

 *  Resolved [betagoo](https://wordpress.org/support/users/betagoo/)
 * (@betagoo)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/performance-problem-many-database-queries/)
 * I have page with several menus
    All menus are displayed in the same time on every
   page of website. Every menu contains a large number of nodes. Every node contains
   posts from category. **And the problem is, the Plugin: category-posts-in-custom-
   menu generate 1200 queries to database.** Not every time the single page is loading.
   It’s happend for every page of website, but only once per browser session. If
   I visit single page first time, loading time is long, the number of queries is
   big. When I refresh page F5, the number of queries is about 100, Plugin: category-
   posts-in-custom-menu generate zero queries. I noticed, the plugin generate many
   update_meta_cache queries. Can you helm pe with this problem?
 * [https://wordpress.org/plugins/category-posts-in-custom-menu/](https://wordpress.org/plugins/category-posts-in-custom-menu/)

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

 *  Plugin Author [Diana van de Laarschot](https://wordpress.org/support/users/anaid/)
 * (@anaid)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/performance-problem-many-database-queries/#post-6821744)
 * Hi betagoo,
 * thank you for reporting this. As it stands, I have never taken performance into
   consideration in the plugin; although the plugin enables you to fill a menu up
   with nothing but categories and posts, it has not been tested with such huge 
   scenarios.
 * The plugin will perform one get_posts call per taxonomy that is ‘unfolded’. I
   will look into it later, to see if I can reduce the number of queries by building
   one single superquery. For now, there isn’t much I can do for you.
 * Question: Those 1200 queries, in what timeframe and how many page requests does
   this involve? Do you have any idea?
 * Kind regards,
    Diana
 *  Plugin Author [Diana van de Laarschot](https://wordpress.org/support/users/anaid/)
 * (@anaid)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/performance-problem-many-database-queries/#post-6821745)
 * I just read up on a few techniques to speed things up, I will look into it for
   the next version of the plugin. Again, thank you for reporting.
 * Kind regards,
    Diana
 *  Thread Starter [betagoo](https://wordpress.org/support/users/betagoo/)
 * (@betagoo)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/performance-problem-many-database-queries/#post-6821778)
 * If you want test my website, pelase write to me at _[Email redacted]_
    I will
   send You full access to my website. This is page for test, so You can do everything.
 *  [Andrew Nevins](https://wordpress.org/support/users/anevins/)
 * (@anevins)
 * WCLDN 2018 Contributor | Volunteer support
 * [10 years, 5 months ago](https://wordpress.org/support/topic/performance-problem-many-database-queries/#post-6821779)
 * [@betagoo](https://wordpress.org/support/users/betagoo/), Please don’t solicit
   private support from these forums.
 *  Thread Starter [betagoo](https://wordpress.org/support/users/betagoo/)
 * (@betagoo)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/performance-problem-many-database-queries/#post-6821780)
 * I don’t need private support.
    I wanted help plugin author. I can give him environment
   for tests.
 *  [Andrew Nevins](https://wordpress.org/support/users/anevins/)
 * (@anevins)
 * WCLDN 2018 Contributor | Volunteer support
 * [10 years, 5 months ago](https://wordpress.org/support/topic/performance-problem-many-database-queries/#post-6821781)
 * The author is doing their best to support you here on the forums. The question
   was;
 * > Those 1200 queries, in what timeframe and how many page requests does this 
   > involve? Do you have any idea?
 *  Thread Starter [betagoo](https://wordpress.org/support/users/betagoo/)
 * (@betagoo)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/performance-problem-many-database-queries/#post-6821811)
 * I can not diagnoze cause of the problem.
    But, problem now is solved. I use Transients
   to cache menu.
 *  Plugin Author [Diana van de Laarschot](https://wordpress.org/support/users/anaid/)
 * (@anaid)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/performance-problem-many-database-queries/#post-6821816)
 * Hi betagoo,
 * I indeed read something about Transients. Did you change any code in the plugin
   to use Transients? (I have never worked with Transients before, tips are welcome
   🙂 )
 * Kind regards,
    Diana
 *  Thread Starter [betagoo](https://wordpress.org/support/users/betagoo/)
 * (@betagoo)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/performance-problem-many-database-queries/#post-6821817)
 * I did not modify the plugin.
    In first occurrence of menu I use transients.
 *     ```
       $header_menu_query = get_transient( 'header_menu_query_');
   
       if( $header_menu_query === false )
       {
   
       $header_menu_query = wp_nav_menu( array( 'menu' => $menu_id, 'container' => '', 'items_wrap' => '%3$s', 'echo' => 0 ) );
   
       set_transient( 'header_menu_query_', $header_menu_query, YEAR_IN_SECONDS );
   
       }
   
       echo $header_menu_query;
       ```
   
 *  Plugin Author [Diana van de Laarschot](https://wordpress.org/support/users/anaid/)
 * (@anaid)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/performance-problem-many-database-queries/#post-6821819)
 * Hi betagoo,
 * the use of transients was what I wanted to investigate. Thank you for sharing!
 * Unfortunately, there is no suitable point in time inside the plugin where I can
   perform this caching and retrieving (other plugins might edit the menu as well)
   so this is indeed the best and only option: To cache the entire menu using transients.
 * I’ll add it to the plugin FAQ.
 * Kind regards,
    Diana

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

The topic ‘Performance problem – many database queries’ is closed to new replies.

 * ![](https://ps.w.org/category-posts-in-custom-menu/assets/icon-128x128.png?rev
   =2539336)
 * [Category Posts in Custom Menu](https://wordpress.org/plugins/category-posts-in-custom-menu/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/category-posts-in-custom-menu/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/category-posts-in-custom-menu/)
 * [Active Topics](https://wordpress.org/support/plugin/category-posts-in-custom-menu/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/category-posts-in-custom-menu/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/category-posts-in-custom-menu/reviews/)

 * 10 replies
 * 3 participants
 * Last reply from: [Diana van de Laarschot](https://wordpress.org/support/users/anaid/)
 * Last activity: [10 years, 4 months ago](https://wordpress.org/support/topic/performance-problem-many-database-queries/#post-6821819)
 * Status: resolved