Home › Forums › Backend Issues (wp-admin) › Display field from another CPT › Reply To: Display field from another CPT
You need to do a reverse relationship query in CPT2 to get the post for CPT1
$args = array(
'post_type' => 'CPT#2',
'posts_per_page' => '1', // assuming there is only one
'meta_query' => array(
array(
'key' => 'RELATIONSHIP_FIELD_NAME',
'value' => '"'.$post->ID.'"',
'compare' => 'LIKE'
)
)
);
$query = new WP_Query($args);
if ($query->have_posts) {
$related_id = $query->posts[0]->ID;
// get field from the other post
$value = get_field('some other field', $related_id);
}
see this page for more on reverse relationship queries https://www.advancedcustomfields.com/resources/querying-relationship-fields/
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.