我正在尝试使用WP\\u query缓存查询返回的数据。
在我指定的时间附近,它似乎没有存储任何内容。有时它会在每次加载页面时刷新。
我可能做错了什么?
<?php
// get our transient data if it exists
// prevents pummelling the database with multiple random queries
$tipsloop = get_transient (\'homepage_tipsloop\');
if (!$tipsloop )
{
echo \'THIS IS NEW TRANSIENT DATA\';
$tipsloop = new WP_Query( array( \'cat\' => \'8\', \'posts_per_page\' => \'1\' , \'orderby\' => \'rand\') );
set_transient (\'homepage_tipsloop\' , $tipsloop , MINUTE_IN_SECONDS * 5 ); // cached for 5 minutes
}
?>
<!-- // Tips Loop -->
<?php while ($tipsloop->have_posts()) : $tipsloop->the_post();
echo get_the_post_thumbnail($page->ID, \'homefooter-thumb\'); ?>
<div class="home-hotspots-tipscopy">
<?php the_content(); ?>
</div>
<p>
<a href="/category/tips/">MORE TIPS</a>
</p>
<?php endwhile; ?>
最合适的回答,由SO网友:Pieter Goosen 整理而成
我已经把我的评论变成了答案。请接受作为解决方案。改变set_transient (\'homepage_tipsloop\' , $tipsloop , MINUTE_IN_SECONDS * 5 );
到set_transient (\'homepage_tipsloop\' , $tipsloop , 5 * MINUTE_IN_SECONDS );
如codex