I'm having trouble trying to display related post content and custom field content from one custom post type to another.
The Custom Post Types and posts are as follows:
CTP1 - page title 1 - page title 2 CTP2 - page title 1 - page title 2
CPT2 posts contain fields created using the Advanced Custom Fields plugin. CPT1 posts contains a Post Object Type field that I can link posts from CPT1 with the same title.
I've also set up a single-CPT1.php template file which I want to display all the content from the CPT1 posts, plus the linked content from the corresponding post in CPT2.
I've search various support pages on ACF for example https://www.advancedcustomfields.com/resources/post-object/ but I am still not able to get this to work.
So my question is how do I write the loop that pulls the corresponding post in CPT2 by the linked post object or by page title and display the custom field content from that post?
Please see my single-cpt1.php code
<?php /* * Loop through post objects (assuming this is a multi-select field) ( don't setup postdata ) * Using this method, the $post object is never changed so all functions need a seccond parameter of the post ID in question. */ $post_objects = get_field('cpt2_related_post'); if( $post_objects ): ?> <?php foreach( $post_objects as $post_object): ?> <div><?php the_field('latest_activities', $post_object->ID); ?></div> <?php endforeach; ?> <?php endif; ?>