Home › Forums › General Issues › Reverse relationship – the_content › Reply To: Reverse relationship – the_content
Hi RBmac,
Been away from the desk. Thanks for responding. Of course, not in the loop – makes total sense and now have it working. Setup_postdata was the answer.
Code for anyone looking for it:
<?php
$args = array(
'post_type' => 'post',
'posts_per_page' => 1,
'meta_query' => array(
array(
'key' => 'field', // name of custom field
'value' => '"' . get_the_ID() . '"',
'compare' => 'LIKE'
)
)
);
$lastposts = get_posts( $args );
foreach ( $lastposts as $post ) :
setup_postdata( $post ); ?>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<p><?php the_content(); ?>
<?php endforeach;
wp_reset_postdata(); ?>
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.