<?php

require 'wp-load.php';

$post_id_with_title    = 10577;
$post_id_without_title = 10558; // Must be post immediately preceding the $post_id_with_title post.

// Initial State
$post_with_title    = get_post( $post_id_with_title );
$post_without_title = get_post( $post_id_without_title );

echo "Initial State\n";
var_dump( $post_with_title->post_title );
// Expected: "This Post Has A Title"
// Actual  : "This Post Has A Title"
var_dump( $post_without_title->post_title );
// Expected: ""
// Actual  : ""

echo "\n";


echo "Trial 1: Do not clear the cache within get_adjacent_post_rel_link()\n";

// Setup global post
$GLOBALS['post'] = $post_with_title;
setup_postdata( $post_with_title );

get_adjacent_post_rel_link();

// Trial 1 Results
$post_with_title    = get_post( $post_id_with_title );
$post_without_title = get_post( $post_id_without_title );

var_dump( $post_with_title->post_title );
// Expected: "This Post Has A Title"
// Actual  : "This Post Has A Title"
var_dump( $post_without_title->post_title );
// Expected: ""
// Actual  : ""

echo "\n";


echo "Trial 2: Clear the cache within get_adjacent_post_rel_link()\n";

// Setup global post
$GLOBALS['post'] = $post_with_title;
setup_postdata( $post_with_title );

// Clear cache within get_adjacent_post_rel_link()
add_filter( 'the_title', function( $title, $post_id ) {
        clean_post_cache( $post_id );
        return $title;
}, 10, 2 );

get_adjacent_post_rel_link();

// Trial 2 Results
$post_with_title    = get_post( $post_id_with_title );
$post_without_title = get_post( $post_id_without_title );

var_dump( $post_with_title->post_title );
// Expected: "This Post Has A Title"
// Actual  : "This Post Has A Title"
var_dump( $post_without_title->post_title );
// Expected: ""
// Actual  : "Previous Post"
