我试图利用ACF关系将成员关联到不同的委员会。在前端,我想知道委员会的名称以及与之相关的董事会成员。我试图遵循ACF Relationship 指南,几个堆栈答案,和其他东西,但我对WP很陌生,所以我一直没有成功。
Here are screenshots of my Wordpress setup
Here is my code:
<?php
$args = array(\'post_type\' => \'committees\');
$the_query = new WP_Query($args);
if (have_posts()):
while ($the_query->have_posts()): $the_query->the_post();
?>
<li style=\'margin-bottom: 15px;\'>
<h5 style=\'margin: 0;\'><?php echo the_field("committee_name"); ?></h5>
<ul>
<li>associated committee members repeated here</li>
</ul>
</li>
<?php
endwhile;
endif;
wp_reset_postdata();
?>
Edits
<?php
$args = array(\'post_type\' => \'committees\');
$the_query = new WP_Query($args);
if (have_posts()):
while ($the_query->have_posts()): $the_query->the_post();
$members = get_field(\'committee_members\', $member->ID);
?>
<li style=\'margin-bottom: 15px;\'>
<h5 style=\'margin: 0;\'><?php echo the_field("committee_name"); ?></h5>
<ul>
<?php foreach($members as $member)
echo "<li>";
echo $member->post_title;
echo "</li>";
?>
</ul>
</li>
<?php
endwhile;
endif;
wp_reset_postdata();
?>

