• Skip to content
  • Skip to primary sidebar
  • Skip to footer

Foliovision

Main navigation

  • Weblog
    • FV Player
    • WordPress
    • Video of the Week
    • Case Studies
    • Business
  • About
    • Testimonials
    • Meet the Team
    • We Support
    • Careers
    • Contact
    • Pricing
  • Products
  • Support
    • FV Player Docs
    • Pro Support
  • Login
  • Basket is empty
Affordable VAST/VPAID for Wordpress has arrived. Serve ads with your videos starting today!

Reducing SQL queries in WordPress Templates

12 May 2010 / Martin / 2 Comments

If you work on a busy WordPress sites in a shared hosting environment, you know how important is to keep the number of MySQL queries down as much as possible. Even if you are using some caching plugin, it’s a matter of principle.

Today I was shocked to see that one of my WordPress templates (it’s based on Cutline template) is taking more than 100 queries on the index page. I was removing various parts of the template until I found that it’s the the_tags() WordPress template tag.

This is the important part of the template:

<div class="entry">
<?php the_excerpt(); ?>
</div>	

<div class="postmetadata">
<p><?php the_tags( 'Tags: ', ', ', ' | ' ); ?></p>
</div>	

And here’s a number of queries going on on my test site right now with this code:

Total Time: 78 database queries run in 0.014724969863892 seconds.

Finally I discovered that if I replace the_excerpt() with the_content() (that means the full articles are displayed, not just first few sentences), the queries go down to around 50. Is the_tags() not working with database cache and global PHP object until the whole content is shown?

I found the exact line in the_content() function which makes this happen and put it into my code, right before the_excerpt:

<div class="entry">
<strong><?php apply_filters('the_content', ''); ?></strong>
<?php the_excerpt(); ?>
</div>	

<div class="postmetadata">
<p><?php the_tags( 'Tags: ', ', ', ' | ' ); ?></p>
</div>	

Now here’s the number of SQL queries: 

Total Time: 47 database queries run in 0.0041866302490234 seconds.

That means the_tags() won’t take any extra queries now. Interesting! If you are developing templates, watch out for this.

The plugin I used to get the exact number of queries is WPDB Profiling.

Martin Vicenik

Martin Viceník

Martin graduated as an engineer in Computer Science from Slovak Technical University in Bratislava. He grew up in Liptovský Mikuláš in northern Slovakia next to the beautiful Tatra mountains. He is the developer behind our FV Player.

Categories: WordPress

Related Posts

  1. FV Testimonials: Guide to Templates

    FV Testimonials: Guide to Templates

  2. FV Testimonials: Guide to Templates – old

    FV Testimonials: Guide to Templates – old

  3. WordPress 4.2 Database Update Difficulties

Reader Interactions

Comments

  1. ivan 3 December 2010 at 5:06 am

    Also, removing tag cloud widget (if you are using) will reduce about 20 queries.

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

You can click here to Subscribe without commenting

Primary Sidebar

Categories

  • Business
  • Camera Reviews
  • Case Studies
  • Design
  • FV Player
  • Internet Marketing
  • IT
  • Life
  • SEO
  • Slovak
  • Video of the Week
  • WordPress

Footer

Our Plugins

  • FV WordPress Flowplayer
  • FV Thoughtful Comments
  • FV Simpler SEO
  • FV Antispam
  • FV Gravatar Cache
  • FV Testimonials

Free Tools

  • Pandoc Online
  • Article spinner
  • WordPress Password Finder
  • Delete LinkedIn Account
  • Responsive Design Calculator
Foliovision logo
All materials © 2025 Foliovision s.r.o. | Panská 12 - 81101 Bratislava - Slovakia | info@foliovision.com
  • This Site Uses Cookies
  • Privacy Policy
  • Terms of Service
  • Site Map
  • Contact
  • Tel. ‭+421 2/5292 0086‬

We are using cookies to give you the best experience on our website.

You can find out more about which cookies we are using or switch them off in .

Powered by  GDPR Cookie Compliance
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

Necessary Cookies

Strictly Necessary Cookie allow you to log in and download your software or post to forums.

We use the WordPress login cookie and the session cookie.

If you disable this cookie, we will not be able to save your preferences. This means that every time you visit this website you will need to enable or disable cookies again.

Support Cookies

Foliovision.com uses self-hosted Rocket.chat and self-hosted Freescout support desk to provide support for FV Player users. These cookies allow our visitors to chat with us and/or submit support tickets.

We are delighted to recommend self-hosted Rocket.chat and especially Freescout to other privacy-conscious independent publishers who would prefer to self-host support.

Please enable Strictly Necessary Cookies first so that we can save your preferences!

3rd Party Cookies

This website uses Google Analytics and Statcounter to collect anonymous information such as the number of visitors to the site, and the most popular pages.

Keeping this cookie enabled helps us to improve our website.

We reluctantly use Google Analytics as it helps us to test FV Player against popular Google Analytics features. Feel free to turn off these cookies if they make you feel uncomfortable.

Statcounter is an independent Irish stats service which we have been using since the beginning of recorded time, sixteen years ago.

Please enable Strictly Necessary Cookies first so that we can save your preferences!