I have two custom post types:
1. Submissions
2. Chapters
A Submission post needs to be associated with a Chapter post. I have a Relationship field to show within a Submission that pulls in the Chapters as a list. I can then associate a Submission with a Chapter via this ACF Relationship field.
Now, when I display a Chapter archive page, I want to show all Submission posts that have the matching relationship set.
Any ideas on how to do this? I’ve tried the ACF Relationship code from the docs within a page template that queries for Chapters like this
<?php
$args = array( 'post_type' => 'chapters', 'posts_per_page' => 10, 'category_name' => 'current' );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
the_title();
endwhile;
$posts = get_field('submission_attachments');
if( $posts ): ?>
<?php foreach( $posts as $post): ?>
<?php setup_postdata($post); ?>
<?php the_title(); ?>
<?php endforeach; ?>
<?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
<?php endif; ?>
Get nothing from that. Any ideas on how to achieve this?
Many thanks
Hi @juxprose
Sounds like you want to perform a revers lookup. This is documented here:
http://www.advancedcustomfields.com/resources/tutorials/querying-relationship-fields/
Please read the docs, try some code and let me know if you have any further questions.
Perfect – did just what I wanted. Thanks Elliot.