Help with WP_Query – Too many mySQL queries

I need some kind of help with wp_query. Am I doing something wrong? I am getting a lot of mySQL queries, while building a new theme.

My WP_Query is:

Read More
<?php
 $args = array(
   'post_type' => 'items',
   'order' => 'ASC',
'posts_per_page' => 4,
 ); ?>

<ul>
<?php $lastitems = new WP_Query( $args);
while ( $lastitems -> have_posts() ) : $lastitems -> the_post();?>
    <li>
    <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail('thumbnail', array('title' => get_the_title())); ?></a>
    Posted: <?php the_time('d M, Y'); ?>  <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"></a>
    </li>
                                    <?php endwhile; ?>
</ul>

Link to pastie.

For this WP_query I’m receiving 5-7 mySQL queries per retrieved info about post.

For example, if i put posts_per_page' => 1 i will get 15 mySQL queries, if i put posts_per_page' => 2 i will get 21 mySQL queries, for 3 is 28, for 10 posts it will be around 60-70 queries just for listings and about 90 mySQL queries in total, etc..

I think that’s a little too much.

Also, get_posts uses the same wp_query, so it’s not helping.
Do you have any idea how to minimize number of mySQL queries, or how to fix my wp_query if I wrote it wrong.

Thanks

Dusan

Related posts

Leave a Reply

1 comment

  1. There is nothing wrong with your query, this is normal for WordPress.

    What is typically more important is the “total query time”. A well written theme with over 100 queries will often ring in under 20 milliseconds, that is 4-20 times faster than the blink of an eye. With a caching plugin you can can reduce this a great deal further.

    If you really want to optimize I suggest you turn on debugging (with debug bar) and check each SQL query to see if there are any loose ends you can remove, especially of you have a lot of sidebars/widgets and multiple loops.