Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question

closed as too localized by toscho 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

1 Answer 1

up vote 0 down vote accepted

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');
share|improve this answer

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