Php Wordpress查询

Php Wordpress查询,php,mysql,wordpress,Php,Mysql,Wordpress,有些事情导致我们的数据库变得疯狂。将这三个查询连成一行是否是一个可能的问题 <ul> <?php query_posts(array('category__in'=>38082, 'order-by'=>'post_date','order'=>'DESC','posts_per_page'=>'5')); while (have_posts()) : the_post(); ?>

有些事情导致我们的数据库变得疯狂。将这三个查询连成一行是否是一个可能的问题

 <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>

第一个类别id是真的吗?此外,如果您运行过多的查询(我在那里看到了三个),并且每个类别中都有大量的帖子,这可能会导致疯狂的行为

query_posts()不是最有效的方法

首先,试着对代码进行注释,以确保重负载不在其他地方

确认问题仍然存在后,尝试从query_posts()切换到get_posts()。我还注意到,您将每页的帖子数作为字符串而不是数字

之后,单个列将如下所示:

<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>

希望有帮助

你能提供更多关于数据库疯狂的细节吗?你在数据库中有多少帖子?30K+篇文章。服务器负载一直在继续,好像一个while循环无限期地进行着。