web-dev-qa-db-fra.com

Champs personnalisés avancés: Post Object - Ne pas renvoyer de données

J'ai un type de message personnalisé appelé "Formation" avec une page d'archive (archive-training.php).

J'ai un autre type de message personnalisé appelé "Cours".

J'utilise Champs personnalisés avancés: Post Object pour relier les publications "Cours" aux publications "Formation" via un seul menu déroulant dans l'écran de modification "Formation" (en d'autres termes, chaque publication "Formation" comporte un "cours" associé. poster).

Dans le fichier archive-training.php, j'ai la boucle suivante:

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

Mais seul le titre du poste "Formation" est en cours de sortie - le titre/cours "Cours" associé ne l'est pas.

Toute aide serait très appréciée.

Acclamations gars.

1
user1385827

Résolu J'ai eu une faute de frappe - ligne 10:

$post_object = get_field('post_object');

aurait dû avoir le nom de mon champ d'objet de publication, à savoir:

$post_object = get_field('myfieldname');
3
user1385827