-
Notifications
You must be signed in to change notification settings - Fork 1
/
example-functions.php
72 lines (58 loc) · 1.41 KB
/
example-functions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
/**
* Example usage.
*
* Instead of calling WP_Query directly, you would write a function
* like below and call it instead. You can treat the results the same
* as the results of WP_Query() or get_posts();
*
*/
/**
* Perform a WP_Query() and cache it.
*
* @param boolean $cache_bust If true, ignores all caches and busts them up.
* @return object WP_Query results.
*/
function wds_query_featured_posts( $cache_bust = false ) {
return wds_cache_wp_query(
// WP_Query args
array(
'posts_per_page' => 3,
'category' => 'featured',
),
// TLC Transient args
array(
'time' => 12 * HOUR_IN_SECONDS,
'cache_bust' => $cache_bust,
)
);
}
/**
* Perform get_posts() and cache it.
*
* @param boolean $cache_bust If true, ignores all caches and busts them up.
* @return array An array of posts.
*/
function wds_get_featured_posts( $cache_bust = false ) {
return wds_cache_get_posts(
// WP_Query args
array(
'posts_per_page' => 3,
'category' => 'featured',
),
// TLC Transient args
array(
'time' => 12 * HOUR_IN_SECONDS,
'cache_bust' => $cache_bust,
)
);
}
/**
* Flush out transients.
*/
function wds_transient_flusher() {
wds_query_featured_posts( true );
wds_get_featured_posts( true );
}
add_action( 'edit_category', 'wds_transient_flusher' );
add_action( 'save_post', 'wds_transient_flusher' );