WP Query Foreach具有无限循环

可信

我需要帮助。我不知道为什么此脚本无限循环,因为我的站点现在不断冻结服务器,即将资源限制到关闭SQL Server的地步。

global $post;
$args = array(
    'posts_per_page'  => 4,
    'numberposts'     => 4,
    'offset'          => 0,
    'category'        => $id,
    'orderby'         => 'post_date',
    'order'           => 'DESC',
    'meta_key'        => '',
    'meta_value'      => '',
    'post_type'       => 'post',
    'post_mime_type'  => '',
    'post_parent'     => '',
    'post_status'     => 'publish',
    'suppress_filters' => true
);
$tips = get_posts( $args ); 
foreach( $tips as $post ) : setup_postdata($post); ?>
    <a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>">
        <?php if(has_post_thumbnail()){ the_post_thumbnail( 'medium', array('itemprop'=>'image') ); } ?>
    </a>

<?php endforeach?>

我该如何解决?谢谢

m1tk00

之后global $post;请添加以下内容

$old_post = $post; 

然后endforeach添加以下内容

wp_reset_postdata()

然后添加

 $post = $old_post;

希望这可以帮助

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章