WordPress.org

Ready to get started?Download WordPress

Forums

Help with WP_Query - Too many mySQL queries (2 posts)

  1. yabate
    Member
    Posted 1 year ago #

    Hello people,

    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:

    <?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: http://pastie.org/5130894)

    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

  2. yabate
    Member
    Posted 1 year ago #

    Any suggestion how to reduce number of mySQL queries? Different approach?

    Thanks

Topic Closed

This topic has been closed to new replies.

About this Topic