I am working on a WordPress site with staff bio pages. At the bottom of the page, I would like to include their most recent blog posts (if they have any). I have an outer loop that pulls the fields from my Advanced Custom Field form and an inner loop where I would like to use their name as an argument for the author. Right now I am pulling all the blog posts and can't seem to figure out how to use the outer loop post info (in this case I either need the $name
variable or the title from the outer loop post data. Or to use the last part of the permalink? Is that possible?
<?php while ( have_posts() ) : the_post();
$name = get_the_title();
$position = get_field("position");
$email = get_field("email");
$image = get_field("photo");
$size = "full";
$bio = get_field("bio");
?>
<div id="primary" class="site-content">
<header id="header" role="banner" class="l-hero-title bio-hero">
</header>
<div id="bio-page" class="l-crew content-wrapper">
<article
itemid="<?php echo the_permalink(); ?>"
itemscope
itemtype="http://schema.org/Person"
>
<figure>
<?php if ($image && isset($image['url'])) {
echo '<img src="' . esc_url($image['url']) . '" alt="' . esc_attr($image['alt']) . '">';
} ?>
</figure>
<h1 class="l-crew-hero__header-name" itemprop="name">
<?php echo $name; ?>
</h1>
<h2 class="l-crew-hero__header-position" itemprop="hasOccupation">
<?php echo $position; ?>
</h2>
<div class="l-crew-contact">
<!-- Email -->
<a class="l-crew-contact__item email" href="mailto:<?php echo $email; ?>" itemprop="email">
<?php echo $email; ?></a>
</div>
<section id="content" class="l-crew-bio__wrapper">
<div class="l-crew-bio">
<p><?php echo $bio; ?></p>
</div>
</section>
</article>
<!-- BLOG POSTS SECTION -->
<section id="posts" class="l-crew__blog-posts-wrapper">
<div class="l-crew-posts">
<h3 class="l-crew-posts__hding">
Blog Posts </h3>
<?php
$auth_query = new WP_Query( array(
'post_author => $name',
'posts_per_page' => 3,
) );
if ($auth_query->have_posts()) :
while ($auth_query->have_posts()) :
$auth_query->the_post();
$title = get_the_title();
$image = get_field("thumbnail");
$date = get_the_date( 'F j, Y' );
?>
<figure class="blog-image c-archive-snippet__img col-md-5">
<?php if ($image && isset($image['url'])) {
echo '<img src="' . esc_url($image['url']) . '" alt="' . esc_attr($image['alt']) . '">';
} ?>
</figure>
<div class="c-archive-snippet-text-wrapper">
<h3 class="c-archive-snippet__title"><?php echo $title ?></h3>
<span class="c-archive-snippet__date"><?php echo $date ?></span>
<div class="read-more-link-container">
<a href="<?php the_permalink(); ?>" class="c-archive-snippet__readmore a-learnmore"><p>Read More</p></a>
</div>
</div>
<?php
endwhile;
endif;
wp_reset_postdata(); ?>
</div>
</section>
</div>
</div>
<?php endwhile;
?>
Any suggestions would be appreciated!!!