1 | <?php |
---|
2 | |
---|
3 | require 'wp-load.php'; |
---|
4 | |
---|
5 | $post_id_with_title = 10577; |
---|
6 | $post_id_without_title = 10558; // Must be post immediately preceding the $post_id_with_title post. |
---|
7 | |
---|
8 | // Initial State |
---|
9 | $post_with_title = get_post( $post_id_with_title ); |
---|
10 | $post_without_title = get_post( $post_id_without_title ); |
---|
11 | |
---|
12 | echo "Initial State\n"; |
---|
13 | var_dump( $post_with_title->post_title ); |
---|
14 | // Expected: "This Post Has A Title" |
---|
15 | // Actual : "This Post Has A Title" |
---|
16 | var_dump( $post_without_title->post_title ); |
---|
17 | // Expected: "" |
---|
18 | // Actual : "" |
---|
19 | |
---|
20 | echo "\n"; |
---|
21 | |
---|
22 | |
---|
23 | echo "Trial 1: Do not clear the cache within get_adjacent_post_rel_link()\n"; |
---|
24 | |
---|
25 | // Setup global post |
---|
26 | $GLOBALS['post'] = $post_with_title; |
---|
27 | setup_postdata( $post_with_title ); |
---|
28 | |
---|
29 | get_adjacent_post_rel_link(); |
---|
30 | |
---|
31 | // Trial 1 Results |
---|
32 | $post_with_title = get_post( $post_id_with_title ); |
---|
33 | $post_without_title = get_post( $post_id_without_title ); |
---|
34 | |
---|
35 | var_dump( $post_with_title->post_title ); |
---|
36 | // Expected: "This Post Has A Title" |
---|
37 | // Actual : "This Post Has A Title" |
---|
38 | var_dump( $post_without_title->post_title ); |
---|
39 | // Expected: "" |
---|
40 | // Actual : "" |
---|
41 | |
---|
42 | echo "\n"; |
---|
43 | |
---|
44 | |
---|
45 | echo "Trial 2: Clear the cache within get_adjacent_post_rel_link()\n"; |
---|
46 | |
---|
47 | // Setup global post |
---|
48 | $GLOBALS['post'] = $post_with_title; |
---|
49 | setup_postdata( $post_with_title ); |
---|
50 | |
---|
51 | // Clear cache within get_adjacent_post_rel_link() |
---|
52 | add_filter( 'the_title', function( $title, $post_id ) { |
---|
53 | clean_post_cache( $post_id ); |
---|
54 | return $title; |
---|
55 | }, 10, 2 ); |
---|
56 | |
---|
57 | get_adjacent_post_rel_link(); |
---|
58 | |
---|
59 | // Trial 2 Results |
---|
60 | $post_with_title = get_post( $post_id_with_title ); |
---|
61 | $post_without_title = get_post( $post_id_without_title ); |
---|
62 | |
---|
63 | var_dump( $post_with_title->post_title ); |
---|
64 | // Expected: "This Post Has A Title" |
---|
65 | // Actual : "This Post Has A Title" |
---|
66 | var_dump( $post_without_title->post_title ); |
---|
67 | // Expected: "" |
---|
68 | // Actual : "Previous Post" |
---|