0

Something is causing our database to go crazy. Is having these three queries in a row a possible problem?

 <ul>
    <?php   
        query_posts(array('category__in'=>38082, 'order-by'=>'post_date','order'=>'DESC','posts_per_page'=>'5')); 
        while (have_posts()) : the_post();
    ?>              

    <li><a href="<?php the_permalink(); ?>"><?php echo the_title()?></a></li>

    <?php endwhile; ?>
    <?php wp_reset_query();?>
 </ul>

 <ul>
    <?php   
        query_posts(array('category__in'=>1, 'order-by'=>'post_date','order'=>'DESC','posts_per_page'=>'5')); 
        while (have_posts()) : the_post();
    ?>              

    <li><a href="<?php the_permalink(); ?>"><?php echo the_title()?></a></li>

    <?php endwhile; ?>
    <?php wp_reset_query();?>
 </ul>      

 <ul>
    <?php   
        query_posts(array('category__in'=>15, 'order-by'=>'post_date','order'=>'DESC','posts_per_page'=>'5')); 
        while (have_posts()) : the_post();
    ?>              

    <li><a href="<?php the_permalink(); ?>"><?php echo the_title()?></a></li>

    <?php endwhile; ?>
    <?php wp_reset_query();?>
 </ul>
4

2 に答える 2

1

Is that first category id real? Also if you run too many queries, which i see three there, and have a high amount of posts in each of those categories, that may cause crazy behavior.

于 2012-09-25T23:06:50.820 に答える
1

query_posts() is not the most efficient method to use.

First of all, try commenting out that code to make sure the heavy load isn't somewhere else.

After you confirm that the problem is still there, try switching from query_posts() to get_posts(). I also noticed that you have the number of posts per page as a string instead of a number.

A single column would look like this after that:

<ul>
    <?php   
    $posts=get_posts( array('cat'=>38082, 'numberposts'=>5)); 
    foreach($posts as $post){ ?>              

        <li><a href="<?php echo get_permalink($post->ID); ?>"><?php echo $post->post_title;?></a></li>

    <?php } ?>
 </ul>

Hope it helps!

于 2012-09-26T00:06:44.690 に答える