Show Related Posts With ACF Plugin

Quick Summary

  • Hand-pick each post's related posts with an ACF Relationship field named related_posts, set to return Post IDs, and list them in single.php.
  • get_field passes the chosen IDs to WP_Query through post__in, and orderby post__in keeps them in the order you picked.
  • If no posts are selected, WordPress ignores the empty post__in and lists regular posts, so check $related_posts before querying.

With the Advanced Custom Fields (ACF) Relationship field, you pick the related posts by hand on each post instead of relying on categories or tags, as tag-based related posts do. This snippet reads that field and lists the chosen posts as links, in the order you picked them.

Create a Relationship field named related_posts and set its Return Format to Post ID, because the IDs are passed straight to WP_Query. Then add the code to your single post template, such as single.php.

PHP
<?php if( function_exists("the_field") ): ?>
<div>
   <h1><?php esc_html_e( 'Related Posts', $domain = 'alpha' ) ?></h1>
   <?php
      $related_posts = get_field( "related_posts" );
      
      $alpha_related_posts = new WP_Query( array(
      
      	'post__in' => $related_posts,
      	'orderby' => 'post__in',
      
      ));
      
      while ( $alpha_related_posts->have_posts() ) {
      
      	$alpha_related_posts->the_post();?>
   <h4><a href="<?php echo the_permalink(  ); ?>"><?php the_title(); ?></a></h4>
   <?php
      }
      wp_reset_query();
      ?>
</div>
<?php endif; ?>

How it works

  • function_exists("the_field") skips the whole block if ACF isn’t active.
  • get_field( "related_posts" ) returns the array of selected post IDs.
  • post__in limits the query to those IDs, and 'orderby' => 'post__in' keeps the order from the field.
  • The loop prints each post’s title as a link, and wp_reset_query() restores the main post afterwards.
  • esc_html_e() prints the translatable heading; replace the alpha text domain with your theme’s.

Things to watch

  • If no related posts are selected, post__in is empty and WordPress ignores it, so the block lists your regular posts instead. Check that $related_posts isn’t empty before running the query.
  • Without a post_type argument the query only returns regular posts. Add one if the field lets you pick pages or custom post types.
  • The number of results is capped by the Blog pages show at most setting under Settings > Reading, since posts_per_page isn’t set.

If you’d like hand-picked related posts and other ACF features built into your theme, see my custom WordPress development services.

See also: Show Social Links For Users By ACF Plugin.

Share on X (opens in a new tab) Share on LinkedIn (opens in a new tab) Share on Facebook (opens in a new tab)

ChatGPT (opens in a new tab) Claude (opens in a new tab) Gemini (opens in a new tab) Perplexity (opens in a new tab) Grok (opens in a new tab)

More Insights

See More