I have a custom post type called "Training" with an archive page (archive-training.php).

I have another custom post type called "Courses".

I am using Advanced Custom Fields: Post Object to link "Courses" posts to "Training" posts via a single select dropdown on the "Training" edit screen (ie. each "Training" post has one related "Courses" post).

In the archive-training.php file I have the following loop:

    <?php while (have_posts()) : the_post(); ?>

<div <?php post_class('loop'); ?> id="post-<?php the_ID(); ?>" >
<div class="post-content">
    <div class="post-title">
            <a href="<?php the_permalink(); ?>" title="<?php printf(esc_attr__('Permalink to %s', 'purepress'), the_title_attribute('echo=0')); ?>" rel="bookmark">
                <?php the_title(); ?>
                    $post_object = get_field('post_object');

                    if( $post_object ): 

                        // override $post
                        $post = $post_object;
                        setup_postdata( $post ); 

                            <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
                        <?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
                <?php endif; ?>

<!-- Post -->
<?php endwhile; // End the loop. Whew.  ?>

But only the "Training" post title is being output - the related "Courses" title/permalink is not.

Any help would be much appreciated.

Cheers guys.

closed as too localized by fuxia May 29 '13 at 22:30

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. If this question can be reworded to fit the rules in the help center, please edit the question.

  • In the field's options, is Select multiple values set to yes or no? – Milo May 27 '13 at 2:29
  • Hi Milo, it it set to "no". – user1385827 May 27 '13 at 3:20
  • can you confirm that your used the name post_object itself? What is your output when you var_dump($post_object)? – RRikesh May 27 '13 at 5:01
  • Bit of a php noob, how would I do the var_dump? – user1385827 May 27 '13 at 5:26
  • Add var_dump($post_object) after $post_object = get_field('post_object'); – RRikesh May 27 '13 at 6:03

Solved. I had a typo - line 10:

$post_object = get_field('post_object');

should have had the name of my post object field ie:

$post_object = get_field('myfieldname');

Not the answer you're looking for? Browse other questions tagged or ask your own question.