0

I am trying to cache the returned data from a query using WP_Query.

It doesn't seem to be storing any where near the time I have specified. Sometimes its refreshing on every page load.

What might I be doing wrong?

<?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;  ?>
1

I've change my comment into an answer. Please accept as solution. Change set_transient ('homepage_tipsloop' , $tipsloop , MINUTE_IN_SECONDS * 5 ); to set_transient ('homepage_tipsloop' , $tipsloop , 5 * MINUTE_IN_SECONDS ); as stated in the codex

| improve this answer | |
  • Thanks i've switched it over. Seems to be working, not sure if its actually setting for 5 mins or not. Will have to do some testing – EHerman Mar 12 '14 at 19:01
  • 1
    have you actually tried this out? the order doesn't matter, 60 * 5 and 5 * 60 are obviously the same result. – Milo Mar 12 '14 at 19:11
  • Yea, obviously would result the same. Seems to be caching appropriately now. I am on a WP Engine account. I went in and purged the cache, and made sure things were caching for around 5 minutes. Your correct, the order does not matter – EHerman Mar 14 '14 at 13:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.