Sunday, 26 May 2013

Advanced Custom Fields: Post Object - Not returning data

Advanced Custom Fields: Post Object - Not returning data

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">
        <h2>
            <a href="<?php the_permalink(); ?>" title="<?php printf(esc_attr__('Permalink to %s', 'purepress'), the_title_attribute('echo=0')); ?>" rel="bookmark">
                <?php the_title(); ?>
                <?php
                    $post_object = get_field('post_object');

                    if( $post_object ):

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

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

<!-- 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.

No comments:

Post a Comment