I have a single page where I display my current post. Within the post loop, I wanna display another loop inside that shows 3 other related posts by title that share the same text as the current post from the field name "category".
Here's a sample of the code that I have as of now. I got the loop within the loop to work, but it's still not showing the related posts.
<!-- View Work -->
<section class="work-single">
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<div class="row">
<div class="medium-12 columns">
<!-- Work Title -->
<div class="intro">
<h1 class="main-title"><?php echo get_the_title(); ?></h1>
</div>
</div>
</div>
<div class="work-show">
<div class="row">
<!-- Slide Show Image -->
<div class="medium-12 columns">
<img src="<?php the_field('large_image'); ?>" alt="">
</div>
<!-- Description -->
<div class="medium-8 columns">
<?php the_field('description'); ?>
</div>
<!-- Information -->
<div class="medium-4 columns">
<ul class="side-info">
<li class="client"><h4><?php the_field('client'); ?></h4></li>
<li class="date"><?php the_field('date'); ?></li>
<li class="category"><?php the_field('category'); ?></li>
<li class="leader"><?php the_field('leader'); ?></li>
</ul>
<!-- Related Posts Loop -->
<ul>
<li>SIMILAR CASE STUDIES</li>
<?php
// args
$args = array(
'post_type' => 'case-studies',
'posts_per_page' => 3,
'meta_key' => 'category',
'orderby' => 'meta_value',
'order' => 'rand'
);
$theposts = get_posts( $args );
foreach($theposts as $post) :
setup_postdata($post);
?>
<li>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</li>
<?php
endforeach;
wp_reset_postdata();
?>
</ul>
</div>
</div>
</div>
<?php endwhile; else: ?>
<p>Sorry, no posts matched your criteria.</p>
<?php endif; ?>