---
description: https://app.gitbook.com/@wordpress-lionel/s/project/transients-ok
---

# Một ví dụ sử dụng Transients (ok)

```
<?php
// Check for transient. If none, then execute WP_Query
if (false === ($featured = get_transient('foo_featured_posts'))) {
  $featured = new WP_Query(
    array(
      'category'       => 'featured',
      'posts_per_page' => 5,
    )
  );
  // Put the results in a transient. Expire after 60 seconds.
  set_transient('foo_featured_posts', $featured, MINUTE_IN_SECONDS);
}
?>
<?php if ($featured->have_posts()): ?>
    <?php while ($featured->have_posts()): $featured->the_post();?>
        // featured posts found, do stuff
    <?php endwhile;?>
<?php else: ?>
    // no featured posts found
<?php endif;?>
<?php wp_reset_postdata();?>
```
