Wordpress - Display List Of Posts Containing a Relationship Field Value [ACF]
I am updating my complete answer based on your clarification in the comment below. I hope this helps:
<div class="entry-content">
<h2>Documents written by this writer</h2>
<?php
/*
* Query posts for a relationship value.
* This method uses the meta_query LIKE to match the string "123" to the database value a:1:{i:0;s:3:"123";} (serialized array)
*/
$documents = get_posts(array(
'post_type' => 'document',
'meta_query' => array(
array(
'key' => 'writer', // name of custom field
'value' => '"' . get_the_ID() . '"', // matches exaclty "123", not just 123. This prevents a match for "1234"
'compare' => 'LIKE'
)
)
));
?>
<?php if( $documents ): ?>
<ul>
<?php foreach( $documents as $document ): ?>
<li>
<a href="<?php echo get_permalink( $document->ID ); ?>">
<?php echo get_the_title( $document->ID ); ?>
</a>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</div>