Show Related Posts With ACF Plugin

Share Now

Share on facebook
Share on pinterest
Share on twitter
Share on linkedin
Share on email

<?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; ?>


Nahid Mahamud

Nahid Mahamud

Web Developer | Graphic Designer | WordPress & Woo-commerce Expert